1
Я использую PHPExcel библиотека, как показано на рисунке here. Но tt работает не так, как ожидалось. Когда я искал, кто-то предложил заменить PHPEXcel_IOFactory
на IOFactory
. Он загружает файл, но он не может быть открыт. Какие-либо предложения?Codeigniter + PHPExcel Library Issue
Вот мой код библиотеки:
Excel.php
require_once APPPATH.'/third_party/PHPExcel.php';
class Excel extends PHPExcel
{
public function __construct()
{
parent::__construct();
}
}
Вот код контроллера:
#load our new PHPExcel library
$this->load->library('excel');
$data = $this->report_model->get_all_report_product_info();
$filename = "Output";
# Set the active Excel worksheet to sheet 0
$this->excel->setActiveSheetIndex(0);
$row_count = 2;
foreach ($data as $row) {
$this->excel->getActiveSheet()->setCellValue('A' . $row_count, $row->product_name);
$this->excel->getActiveSheet()->setCellValue('B' . $row_count, $row->product_sku);
$this->excel->getActiveSheet()->setCellValue('C' . $row_count, $row->customer_name);
$this->excel->getActiveSheet()->setCellValue('D' . $row_count, $row->site_url);
$row_count++;
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
header('Cache-Control: max-age=0');
// Instantiate a Writer to create an OfficeOpenXML Excel .xlsx file
$objWriter = IOFactory::createWriter($this->excel, 'Excel5');
// Write the Excel file to filename
$objWriter->save('php://output');