我正在尝试使用phpexcel将数据导出到excel,但它返回此错误,但指定的excel文件在该位置突出显示。问题是excel文件在那个位置,但一旦它返回该错误,文件就无处可寻,我没做错的是什么?
错误:
致命错误:在C:\ server中显示消息“文件zip://workbooks/NDQA201303001/NDQA201303001.xlsx#xl/media/nqcl1.png”的未捕获异常“异常” \ htdocs中\ NQCL \应用\ THIRD_PARTY \ PHPExcel \作家\ Excel2007中\ ContentTypes.php:216
处理过程的web脚本代码
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("workbooks/" . $labref . "/" . $labref . ".xlsx");
$objPHPExcel->getActiveSheet(0)
->setCellValue('E22', 'Tabs/Capsule Weight')
->setCellValue('E23', 'No.')
->setCellValue('F23', 'Tabs/Capsule Weights (mg)');
$dir = "workbooks";
if (is_dir($dir)) {
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("workbooks/" . $labref . "/" . $labref . ".xlsx");
echo 'Data exported';
} else {
echo 'Dir does not exist';
}
答案 0 :(得分:0)
如果您使用Codeigntier将查询中的数据导出到excel非常简单。你不需要php excel。所有资源都可以在Codeigniter中找到。
看看我的这个答案,这可能对你有所帮助。它将以csv格式导出数据,您可以使用xlsx更改这些数据。
答案 1 :(得分:-1)
使用下面的代码并根据您的要求进行更改。这很好。
<?php
include("config.php");
$result = mysql_query("SELECT * FROM recruitment" );
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
function xlsWriteString( $Row , $Col , $Value )
{
$L = strlen( $Value );
echo pack( "ssssss" , 0x204 , 8 + $L , $Row , $Col , 0x0 , $L );
echo $Value;
return;
}
// Send Header
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=export.xls ");
header("Content-Transfer-Encoding: binary ");
// XLS Data Cell
xlsBOF();
xlsWriteLabel(1,0,"Application No");
xlsWriteLabel(1,1,"Date of Application");
$xlsRow = 2;
while($row = mysql_fetch_array($result))
{
$applicationno=$row['applicationno'];
$dateofapplication=$row['dateofapplication'];
//echo $salarydetails;
xlsWriteNumber($xlsRow,0,"$applicationno");
xlsWriteNumber($xlsRow,1,"$dateofapplication");
$xlsRow++;
}
xlsEOF();
exit();
//}
?>