2015-09-20 111 views
1

我正在使用PHPExcel庫如圖所示here。但是,tt沒有按預期工作。當我搜索時,有人建議將PHPEXcel_IOFactory更換爲IOFactory。它下載文件,但無法打開。有什麼建議麼?Codeigniter + PHPExcel Library問題

這裏是我的庫代碼:

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'); 

回答

0
$objWriter = IOFactory::createWriter($this->excel, 'Excel5'); 

「Excel5」 是舊的電子表格格式(用於.XLS文件)。如果你想創建一個XLSX文件,你需要使用「Excel2007」。