PHPExcel 使用注意事項 與 Demo範例說明
PHPExcel官網:http://www.codeplex.com/PHPExcel
PHPExcel官方下載: http://phpexcel.codeplex.com/releases/
重要指令彙整:
//合併儲存隔
$objPHPExcel->getActiveSheet()->mergeCells("A1:D2");
//設定漸層背景顏色雙色(灰/白)
$objPHPExcel->getActiveSheet()->getStyle("A1:D1")->applyFromArray(
array(
"font" => array(
"bold" => true
),
"alignment" => array(
"horizontal" => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
),
"borders" => array(
"top" => array(
"style" => PHPExcel_Style_Border::BORDER_THIN
)
),
"fill" => array(
"type" => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
"rotation" => 90,
"startcolor" => array(
"rgb" => "DCDCDC"
),
"endcolor" => array(
"rgb" => "FFFFFF"
)
)
)
);
//設定字型大小
$objPHPExcel->getActiveSheet()->getStyle("A1")->getFont()->setSize(10);
//設定字體顏色
$objPHPExcel->getActiveSheet()->getStyle("A1")->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLUE);
//設定背景顏色單色
$objPHPExcel->getActiveSheet()->getStyle("A5:D6")->applyFromArray(
array("fill" => array(
"type" => PHPExcel_Style_Fill::FILL_SOLID,
"color" => array("rgb" => "D1EEEE")
),
)
);
// 增加些資料上來
echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello 番薯!')
->setCellValue('B2', 'world 芋頭!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A4', 'This is the testing. ')
->setCellValue('A5', '烤翻薯-許功蓋 中文測試!');
#Excel實際輸出截圖
Referene:
1. PHPExcel 資源
PHPExcel官網:http://www.codeplex.com/PHPExcel
PHPExcel官方下載: http://phpexcel.codeplex.com/releases/
2. 隨意窩-hugh77417051
http://blog.xuite.net/hugh77417051/wretch/181832737-%E3%80%90PHP%E3%80%91PHPExcel+%E4%BD%BF%E7%94%A8%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A0%85+%E8%88%87+Demo+%E5%8C%AF%E5%87%BA+xls+xlsx
3. PHP官方fputcsv — Format line as CSV and write to file pointer
http://php.net/manual/en/function.fputcsv.php
4. 中文PHP fputcsv()函数教學
http://www.w3school.com.cn/php/func_filesystem_fputcsv.asp
George Huang烤蕃薯 @ Taipei
沒有留言:
張貼留言