Home >Backend Development >PHP Tutorial >yii phpexcel automatically generates files and saves them to the server_PHP tutorial
I recently completed a report task. I had to export the table and send it to the administrator via email in excel format every day. I used phpexcel to save the table to the server, and then sent it through phpmailer.
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);
Note that when you open the generated excel again, an fopen permission error will appear when you generate it again. Helpful message, haha