簡體   English   中英

在Excel中打開創建的文件時出現PHPExcel錯誤

[英]PHPExcel error when opening created File in EXCEL

我使用php-script創建一個使用PHPExcel庫的簡單.xlsx文件。 但是,當我想在Win7的MS Excel 2010中打開它時,收到一條錯誤消息,提示文件格式錯誤或文件已損壞。 從互聯網上嘗試了幾種可能的解決方案,但對我沒有任何幫助。

公共函數createControllingFile($ suffix){$ this-> PHPExcel = new PHPExcel();

    $year = date('y');

    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Cache-Control: max-age=0');


    $this->objWriter = PHPExcel_IOFactory::createWriter($this->PHPExcel, 'excel5');


    $this->objWriter->save('tmp/controlling_'.$year.'_'.$suffix.'.xlsx');

    $_SESSION['counter'] = 0;

    exit();
}

希望你能幫助我,這次會議的事情是數點東西

$this->objWriter->save('tmp/controlling_'.$year.'_'.$suffix.'.xlsx'); 

保存到服務器文件系統上的文件,並且沒有任何內容發送到客戶端瀏覽器。

如果要發送到客戶端的瀏覽器,請將該行更改為:

$this->objWriter->save('php://output');

就像在/ Tests或/ Examples目錄中的01simple-download-xlsx.php中一樣

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM