日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php 生成excel空白,phpexcel库在localhost上运行良好,但在服务器中生成空白的excel文件...

發布時間:2025/3/11 php 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 生成excel空白,phpexcel库在localhost上运行良好,但在服务器中生成空白的excel文件... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這是我的代碼,在本地主機上可以很好地使用數據庫中的數據生成一個excel文件,但在托管服務器中它會生成一個空白的excel文件:

// Starting the PHPExcel library

$this->load->library('PHPExcel');

//$this->load->library('PHPExcel/IOFactory');

$objPHPExcel = new PHPExcel();

$objPHPExcel->getProperties()->setTitle("export")->setDescription("none");

$objPHPExcel->setActiveSheetIndex(0);

// Field names in the first row

$fields = $query->list_fields();

$col = 0;

foreach ($fields as $field)

{

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);

$col++;

}

//format the column sizes

$sheet = $objPHPExcel->getActiveSheet();

$cellIterator = $sheet->getRowIterator()->current()->getCellIterator();

$cellIterator->setIterateOnlyExistingCells( true );

/** @var PHPExcel_Cell $cell */

foreach( $cellIterator as $cell ) {

$sheet->getColumnDimension( $cell->getColumn() )->setAutoSize( true );

}

//var_dump($query->result());

//die;

// Fetching the table data

$row = 2;

foreach($query->result() as $data)

{

$col = 0;

foreach($fields as $field)

{

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $data->$field);

$col++;

}

$row++;

}

$objPHPExcel->setActiveSheetIndex(0);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

header('Content-Disposition: attachment;filename="01simple.xlsx"');

header('Cache-Control: max-age=0');

ob_clean();

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

解決方法:

我認為問題與phpexcel無關.我早些時候遇到過類似的問題,后來發現CI的list_fields()函數在某些linux服務器中不起作用.您可以通過靜態放置字段名稱而不是使用此功能來檢查此方面.

標簽:codeigniter,phpexcel,php

來源: https://codeday.me/bug/20191026/1937839.html

總結

以上是生活随笔為你收集整理的php 生成excel空白,phpexcel库在localhost上运行良好,但在服务器中生成空白的excel文件...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。