php_export_html_to_excel_via_phpexcel
補充一些進階應用:
$objPHPExcel = $objWriter->getPHPExcel();
//抓最大的行列
$str_col = $objPHPExcel->setActiveSheetIndex(0)->getHighestColumn(); //最大列號 eg.J
$str_row = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow(); //最大行數 eg.21
$str_dim = $objPHPExcel->setActiveSheetIndex(0)->calculateWorksheetDimension(); //最大行列 eg.A1:J21
//自動欄寬
foreach(range('A',$str_col) as $columnID) {
$objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
}
//自動換行
$objPHPExcel->getActiveSheet()->getStyle($str_dim)->getAlignment()->setWrapText(true);
$objWriter->save($excelFile);
No comments:
Post a Comment