PHPExcel在PDF上设置了多个页面

时间:2016-07-16 01:03:13

标签: php pdf phpexcel

我正在尝试通过创建新的“表格”来获取我的PHPExcel代码以获取PDF上的多个页面。我有这个例子可以帮助你。

include_once 'Classes/PHPExcel.php';
include_once 'Classes/PHPExcel/IOFactory.php';
$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF;
$rendererLibraryPath = dirname(__FILE__).'/tcpdf';

$objPHPExcel = new PHPExcel();
$objSheetRes = $objPHPExcel->setActiveSheetIndex(0);

$objSheetRes->setTitle('Title');
$objPHPExcel->createSheet()->setTitle('Title 2');

$objPHPExcel->getActiveSheet()->setCellValue('A1', 'SHEET 1');


if (!PHPExcel_Settings::setPdfRenderer($rendererName,$rendererLibraryPath)) {
    die('NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
        '<br />' .
        'at the top of this script as appropriate for your directory structure');
}

header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename= "example.pdf"');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->save('php://output');
exit;

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

你真的需要多少例子?

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->setSheetIndex(1);
$objWriter->save('php://output');

将生成显示第二个工作表的报告(工作表从0开始编制索引)

答案 1 :(得分:0)

我遇到了同样的问题,我用以下方法解决了这个问题:

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->writeAllSheets();  //This allow export multiple sheets
$objWriter->save('php://output');

检查以下内容:https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/10-Reading-and-Writing.md#write-all-worksheets