[英]Codeigniter + PHPExcel Library Issue
我使用PHPExcel庫如圖所示這里 。 但是,tt無法正常工作。 當我搜索時,有人建議將PHPEXcel_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');
$objWriter = IOFactory::createWriter($this->excel, 'Excel5');
“ Excel5”是舊的電子表格格式(用於.XLS文件)。 如果要創建XLSX文件,則需要使用“ Excel2007”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.