利用phpexcel插件如何导出pdf格式的文件?

浏览:10942 发布日期:2015/06/28 分类:求助交流 关键字: phpexcel
到处xls格式的没有问题,我现在导出成pdf格式就报错了...
我的主要代码如下:
public function echoExecl(){
error_reporting(E_ALL);

Vendor('PhpExcel.PHPExcel');
Vendor('PhpExcel.PHPExcel.IOFactory');
Vendor('PhpExcel.PHPExcel.Writer.Excel5');
Vendor('PhpExcel.PHPExcel.Writer.PDF');

$objPHPExcel = new PHPExcel();

...........

$m_exportType = "pdf";
// 如果需要输出EXCEL格式
if($m_exportType=="excel"){
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
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/vnd.ms-excel;");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
$fileName = "库存统计_" . $_SESSION["user_name"] . "_" . date('Ymd') . ".xls";
header("Content-Disposition:attachment;filename=".$fileName);
header("Content-Transfer-Encoding:binary");
$objWriter->save("php://output");
}
// 如果需要输出PDF格式
if($m_exportType=="pdf"){
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->setSheetIndex(0);
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/pdf");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
$fileName = "库存统计_" . $_SESSION["user_name"] . "_" . date('Ymd') . ".pdf";
header("Content-Disposition:attachment;filename=".$fileName);
header("Content-Transfer-Encoding:binary");
$objWriter->save("php://output");
}

exit;
}

这样的话报错:
PDF Rendering library has not been defined.
如果引入:
Vendor('PhpExcel.PHPExcel.Writer.PDF.DomPDF');
又报报错:
Unable to load PDF Rendering library
请问这个怎么处理?
最佳答案
评论( 相关
后面还有条评论,点击查看>>