Ошибка phpexcel
Пытаюсь данные из php оформить в таблицу excel:
include_once "../phpexcel/PHPExcel.php";
$phpexcel = new PHPExcel();
for($j = 0;$j < count($titles);$j++){
$string = $titles[$j]['name'];
$string = mb_convert_encoding($string, "UTF-8","Windows-1251");
$cellLetter = $titles[$j]['cell'] . 1;
$phpexcel->getActiveSheet()->setCellValueExplicit($cellLetter, $string, PHPExcel_Cell_DataType::TYPE_STRING);
}
$j = 2;
foreach ($report_data as $elem) {
$string = $elem['education_level'];
$string = mb_convert_encoding($string, "UTF-8","Windows-1251");
$phpexcel->getActiveSheet()->setCellValueExplicit("A$j", $string, PHPExcel_Cell_DataType::TYPE_STRING);
$string = $elem['e_program'];
$string = mb_convert_encoding($string, "UTF-8","Windows-1251");
$phpexcel->getActiveSheet()->setCellValueExplicit("B$j", $string, PHPExcel_Cell_DataType::TYPE_STRING);
$string = $elem['discipline_cycle'];
$string = mb_convert_encoding($string, "UTF-8","Windows-1251");
$phpexcel->getActiveSheet()->setCellValueExplicit("C$j", $string, PHPExcel_Cell_DataType::TYPE_STRING);
$string = $elem['year'];
$string = mb_convert_encoding($string, "UTF-8","Windows-1251");
$phpexcel->getActiveSheet()->setCellValueExplicit("D$j", $string, PHPExcel_Cell_DataType::TYPE_STRING);
$phpexcel->getActiveSheet()->setCellValueExplicit("E$j", $elem['course']);
$phpexcel->getActiveSheet()->setCellValueExplicit("F$j", $elem['semestr']);
$phpexcel->getActiveSheet()->setCellValueExplicit("G$j", $elem['flow']);
$string = $elem['module'];
$string = mb_convert_encoding($string, "UTF-8","Windows-1251");
$phpexcel->getActiveSheet()->setCellValueExplicit("H$j", $string, PHPExcel_Cell_DataType::TYPE_STRING);
$string = $elem['discipline'];
$string = mb_convert_encoding($string, "UTF-8","Windows-1251");
$phpexcel->getActiveSheet()->setCellValueExplicit("I$j", $string, PHPExcel_Cell_DataType::TYPE_STRING);
$phpexcel->getActiveSheet()->setCellValueExplicit("J$j", $elem['credits']);
$phpexcel->getActiveSheet()->setCellValueExplicit("K$j", $elem['all_hours']);
$phpexcel->getActiveSheet()->setCellValueExplicit("L$j", $elem['lections']);
$phpexcel->getActiveSheet()->setCellValueExplicit("M$j", $elem['practices']);
$phpexcel->getActiveSheet()->setCellValueExplicit("N$j", $elem['laboratory']);
$phpexcel->getActiveSheet()->setCellValueExplicit("O$j", $elem['srsp']);
$phpexcel->getActiveSheet()->setCellValueExplicit("P$j", $elem['srs']);
$phpexcel->getActiveSheet()->setCellValueExplicit("Q$j", $elem['control_work']);
$string = $elem['department'];
$string = mb_convert_encoding($string, "UTF-8","Windows-1251");
$phpexcel->getActiveSheet()->setCellValueExplicit("R$j", $string, PHPExcel_Cell_DataType::TYPE_STRING);
$string = $elem['availability_teacher'];
$string = mb_convert_encoding($string, "UTF-8","Windows-1251");
$phpexcel->getActiveSheet()->setCellValueExplicit("S$j", $string, PHPExcel_Cell_DataType::TYPE_STRING);
$string = $elem['clin_department'];
$string = mb_convert_encoding($string, "UTF-8","Windows-1251");
$phpexcel->getActiveSheet()->setCellValueExplicit("T$j", $string, PHPExcel_Cell_DataType::TYPE_STRING);
$j++;
}
for($i = 0;$i < count($titles);$i++){
$columnLetter = $titles[$i]['cell'];
$phpexcel->getActiveSheet()->getColumnDimension($columnLetter)->setWidth(40);
}
$page = $phpexcel->setActiveSheetIndex();
$page->setTitle("Название");
$objWriter = PHPExcel_IOFactory::createWriter($phpexcel,'Excel2007');
$filename = "Название.xlsx";
$objWrirer->save($filename);
Но получаю следующую ошибку: Fatal error: Uncaught Error: Call to a member function save() on null in D:\open_server\OpenServer\domains\filepath:249 Stack trace: #0 {main} thrown in
Ответы (1 шт):
Автор решения: dinario
→ Ссылка
Fatal error: Uncaught Error: Call to a member function save() on null
Дословно: вызов функции save() у null.
$objWriter != $objWrirer