无法删除缓冲区。没有要删除的缓冲区
2022-08-30 11:37:48
我正在尝试从下面的代码中生成扩展名.xlsx excel文件。我能够很好地下载该文件,但是当我使用Excel工作表打开它时,我收到以下警告错误.Excel 无法打开文件“dindi.xlsx”,因为文件格式或文件扩展名无效。确保文件未损坏,并且文件扩展名与文件格式匹配。当我用记事本打开它时,该文件有以下错误:
注意:ob_end_clean() [ref.outcontrol]:无法删除缓冲区。没有要删除的缓冲区
以下是我正在尝试执行的操作的代码。
public function exportResults() {
$this -> load -> database();
$query = $this -> db -> query("
SELECT * FROM farm LIMIT 10");
$results = $query -> result_array();
$objPHPExcel = new Excel();
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load('./files/farmdetails.xlsx');
$objPHPExcel ->getActiveSheet()->setTitle('farmreport');
$objPHPExcel -> setActiveSheetIndex(0);
$i = 1;
foreach ($results as $result) {
$objPHPExcel -> getActiveSheet() -> SetCellValue('A' . $i, $result["name"]);
$objPHPExcel -> getActiveSheet() -> SetCellValue('B' . $i, $result["dateofcontract"]);
$objPHPExcel -> getActiveSheet() -> SetCellValue('C' . $i, $result["leasorname"]);
$objPHPExcel -> getActiveSheet() -> SetCellValue('D' . $i, $result["acre"]);
$objPHPExcel -> getActiveSheet() -> SetCellValue('E' . $i, $result["zone"]);
$i++;
echo $result["name"];
}
ob_end_clean();
$filename = "dindi.xlsx";
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename=' . $filename);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
$objWriter -> save('php://output');
$objPHPExcel -> disconnectWorksheets();
unset($objPHPExcel);
}