0
我有一個網站,我想用PHPExcel創建一個報告文件。 我爲第一張紙做了兩個循環,我有一個星期的摘要,另一個週期是一週的每一天。 我找回這個錯誤與我的腳本: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');
我該如何解決這個問題?
我的錯誤+1爲儘快答案儘快我接受答案感謝 –
不客氣:)順便說一句,像NetBeans這樣的好IDE可能會指出它;)我拒絕使用完整的IDE多年,幾個月後它就是值得的。 – Jessica