簡體   English   中英

Probloem使用PHPExcel PHP保存到Excel

[英]Probloem Save to Excel using PHPExcel PHP

保存文件時,我對我的PHPExcel感到困惑。 這是我的代碼

$filename = 'test';
$objReader = PHPExcel_IOFactory::createReader('Excel5');

$template = 'C:/xampp5.9/htdocs/MTD/assets/media/template/test.xls'; 

$objPHPExcel = $objReader->load($template);

$objPHPExcel->getSheet(0)->mergeCells('A9:B9')->setCellValue('A9', 'Test');
$rows = 15;
$col = 0;

$dt_download = ['rizky', 'Arie', 'Ester'];

for ($i=0; $i < COUNT($dt_download); $i++) {
 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+$i, $rows+$i, $dt_download[$i]);
}

$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'.xls"');
header('Cache-Control: max-age=0');

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

我只是在我的控制台中有這樣的結果: 在此輸入圖像描述

沒有任何文件作為下載文件。 請告訴我如何解決它,因為我的控制台代碼中沒有任何錯誤。

我正在使用post方法

在這一行

$objPHPExcel->getSheet(0)->mergeCells('A9:B9')->setCellValue('A9', Test);

你在哪里定義了Test。 它是常量,字符串還是什么樣的變量?

因為它會產生錯誤

Warning: Cannot modify header information - headers already sent by

而且你的代碼不起作用。

如果Test只是一個字符串,那么你必須把它放在像這樣的引號中

 $objPHPExcel->getSheet(0)->mergeCells('A9:B9')->setCellValue('A9', 'Test');

暫無
暫無

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

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