最近再整一個報表任務,每天必須把表導出來按excel格式發送郵件給管理員,利用phpexcel把表保存到服務器上,然後再通過phpmailer發送就ok.
ob_end_clean();
ob_start();
$objectPHPExcel = new PHPExcel();
$objectPHPExcel->setActiveSheetIndex(0);
$objectPHPExcel->setActiveSheetIndex(0)->setCellValue("A$i",$resource->source_name);
$objectPHPExcel->setActiveSheetIndex(0)->setCellValue("B$i", $one);
$objectPHPExcel->setActiveSheetIndex(0)->setCellValue("C$i", $two);
$objectPHPExcel->setActiveSheetIndex(0)->setCellValue("D$i", $three);
$objectPHPExcel->setActiveSheetIndex(0)->setCellValue("E$i", $price);
$objectPHPExcel->setActiveSheetIndex(0)->setCellValue("F$i", $goods_price);
$objectPHPExcel->setActiveSheetIndex(0)->setCellValue("G$i", $product);
$objectPHPExcel->setActiveSheetIndex(0)->setCellValue("H$i", $count);
$filename = "c.xls";
$objWriter = PHPExcel_IOFactory::createWriter($objectPHPExcel, 'Excel5');
$objWriter->save($filename);
注意再生成的時候打開生成的excel,再次生成就會出現fopen權限報錯。幫助到的留言,哈哈