0

我正在尝试使用 phpexcel 将数据导出到 excel,但它返回此错误,但指定的 excel 文件在该位置突出显示。问题是excel文件在那个位置,但是一旦它返回那个错误,文件就找不到了,我做错了什么?

错误:

致命错误:C:\server\htdocs\NQCL\application\third_party\PHPExcel 中的消息“文件 zip://workbooks/NDQA201303001/NDQA201303001.xlsx#xl/media/nqcl1.png 不存在”未捕获的异常“异常” \Writer\Excel2007\ContentTypes.php:216

处理进程的网页脚本代码

  $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';
        }
4

2 回答 2

0

如果您使用 Codeigntier 将数据从查询导出到 Excel,这非常容易。您不需要为此使用 php excel。Codeigniter 中提供了所有资源。

看看我的这个答案,这可能对你有帮助。它将以 csv 格式导出数据,您可以使用 xlsx 进行更改。

Codeigniter 中的报告

于 2013-04-18T09:00:31.893 回答
-1

Use the bellow code and change it as per your requirements.This works fine.

<?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();

//}
?>
于 2013-04-18T07:56:54.153 回答