本文介绍了PHPExcel保存PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮帮我,我想将excel保存为pdf格式代码:

Help me i want to save excel in pdf formatThe code:

include_once 'Classes/PHPExcel.php';
/** PHPExcel_IOFactory */
require_once ('Classes/PHPExcel/IOFactory.php');
include_once ('Classes/PHPExcel/Writer/Excel2007.php');
include_once ('Classes/PHPExcel/Writer/PDF.php');

include_once ('Classes/PHPExcel/Writer/PDF/DomPDF.php');


$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
//$rendererLibrary = 'tcPDF5.9';
//$rendererLibrary = 'mPDF5.4';
$rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = '/' . $rendererLibrary;
$objPHPExcel->getActiveSheet()->setTitle('Orari');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->setSheetIndex(0);
$objWriter->save('esp.pdf');

我想保存为pdf格式,但是当我尝试保存时,我收到来自phpexcel的错误响应:致命错误:C:\ xampp \ htdocs \ fserv \ Classes \ PHPExcel \ Writer \ PDF \ DomPDF.php:34堆栈跟踪中未捕获的异常"PHPExcel_Writer_Exception",消息为无法加载PDF渲染库" :#0 C:\ xampp \ htdocs \ fserv \ esportatore.php(190):include_once()#1 C:\ xampp \ htdocs \ fserv \ index.php(44):include('C:\ xampp \ htdocs. ..')#2 {main}放在 34
C:\ xampp \ htdocs \ fserv \ Classes \ PHPExcel \ Writer \ PDF \ DomPDF.php 中/>

I want to save in pdf format, but when i try to save i have an error response from phpexcel:Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'Unable to load PDF Rendering library' in C:\xampp\htdocs\fserv\Classes\PHPExcel\Writer\PDF\DomPDF.php:34 Stack trace: #0 C:\xampp\htdocs\fserv\esportatore.php(190): include_once() #1 C:\xampp\htdocs\fserv\index.php(44): include('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\fserv\Classes\PHPExcel\Writer\PDF\DomPDF.php on line 34

推荐答案

您需要DomPDF才能呈现PDF.检查您是否拥有DomPDF库,否则请按照以下步骤下载并实现它:

You need DomPDF for rendering the PDF. Check if you have the DomPDF library, otherwise download and implement it as follow:

$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = dirname(__FILE__). 'libs/classes/dompdf' . $rendererLibrary;

这篇关于PHPExcel保存PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 18:49