代码点火器+;PHPExcel库问题
我正在使用PHPExcel库,如图所示。但是,tt没有按预期工作。当我搜索时,有人建议将代码点火器+;PHPExcel库问题,php,codeigniter,phpexcel,Php,Codeigniter,Phpexcel,我正在使用PHPExcel库,如图所示。但是,tt没有按预期工作。当我搜索时,有人建议将PHPEXcel\u IOFactory替换为IOFactory。它下载文件,但无法打开。有什么建议吗 这是我的库代码: Excel.php require_once APPPATH.'/third_party/PHPExcel.php'; class Excel extends PHPExcel { public function __construct() { parent
PHPEXcel\u IOFactory
替换为IOFactory
。它下载文件,但无法打开。有什么建议吗
这是我的库代码:
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');
“Excel5”是旧的电子表格格式(用于.XLS文件)。如果要创建XLSX文件,需要使用“Excel2007”
“Excel5”是旧的电子表格格式(用于.XLS文件)。如果要创建XLSX文件,需要使用“Excel2007”
$objWriter = IOFactory::createWriter($this->excel, 'Excel5');