2014-02-06 136 views
3

幫助我,我要保存爲PDF格式 代碼擅長:PHPExcel保存PDF

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無法加載PDF渲染庫的未捕獲異常'PHPExcel_Writer_Exception':34堆棧跟蹤:#0 C: \ xampp \ htdocs \ fserv \ esportatore.php(190):include_once()#1 C:\ xampp \ htdocs \ fserv \ index.php(44):include('C:\ xampp \ htdocs ...')# 2 {main}拋出C:\ xampp \ htdocs \ fserv \ Classes \ PHPExcel \ Writer \ PDF \ DomPDF.php on line

+0

http://stackoverflow.com/questions/20409494/how-to-configure-phpexcel-for-pdf –

回答

7

您需要使用DomPDF來渲染PDF。檢查是否有DOMPDF庫,否則下載並執行它如下:

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

DOMPDF,MPDF或tcPDF ....都可以使用,只要renderername和librarypath配置正確 –

+0

需要放置這個變量的位置** $ renderLibraryPath **?它作爲參數傳遞嗎? –

+4

找到了。它需要使用這些參數調用函數setPdfRenderer'PHPExcel_Settings :: setPdfRenderer($ rendererName,$ rendererLibraryPath);' –