我有一个网站,我想用 PHPExcel 创建一个报告文件。我为第一张有一周总结的表格制作了两个周期,为一周中的每一天制作了另一个周期。我用我的脚本检索此错误:
Catchable fatal error: Argument 1 passed to PHPExcel_IOFactory::createWriter() must be an instance of PHPExcel, null given, called in /var/www/reports/generate_reports_settimanale.php on line 79 and defined in /var/www/inc/PHPExcel/IOFactory.php on line 132
这是我的简化代码:
require_once '../inc/PHPExcel.php';
require_once '../inc/PHPExcel/IOFactory.php';
objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Alessandro Minoccheri")
->setLastModifiedBy("Alessandro Minoccheri")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Generazione report inverter")
->setKeywords("office 2007 openxml php")
->setCategory("");
$row=1;
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow('0', $row, 'Inverter');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow('1', $row, 'Channel');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow('0', 1, 'inverter');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow('1', 1, 'channel');
$objPHPExcel->setActiveSheetIndex(0);
$objWriter3 = PHPExcel_IOFactory::createWriter($objPHPExcel3, 'Excel5');
$week_end = date( 'Y-m-d 23:59:59', $start + ( 6 * 86400 ) );
$week_start = date( 'Y-m-d 00:00:00', $start );
$date = $week_start;
while (strtotime($date) <= strtotime($week_end)) {
$date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
$objWorkSheet = $objPHPExcel->createSheet($date); //Setting index when creating
//Write cells
$objWorkSheet->setCellValue('A1', 'Hello'.$i)
->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');
// Rename sheet
$objWorkSheet->setTitle("test");
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="report.xls"');
header('Cache-Control: max-age=0');
$objWriter3->save('php://output');
我该如何解决这个问题?