Createsheet function is not inserting the page in pdf file

Topics: Developer Forum, Project Management Forum, User Forum
Nov 15, 2010 at 11:40 AM

Hi ,

<?php
/** Error reporting */
error_reporting(E_ALL);

/** PHPExcel */
require_once 'Classes/PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
        ->setLastModifiedBy("Maarten Balliauw")
        ->setTitle("PDF Test Document")
        ->setSubject("PDF Test Document")
        ->setDescription("Test document for PDF, generated using PHP classes.")
        ->setKeywords("pdf php")
        ->setCategory("Test result file");

// Assign cell values
            $objPHPExcel->setActiveSheetIndex(0);
            $objPHPExcel->getActiveSheet()->setCellValue("A1", "cell value here 111");

            $objPHPExcel->createSheet();
            $objPHPExcel->setActiveSheetIndex(1);
            $objPHPExcel->getActiveSheet()->setCellValue("A2", "cell value here 2222222222");

$objPHPExcel->createSheet();
            $objPHPExcel->setActiveSheetIndex(2);
            $objPHPExcel->getActiveSheet()->setCellValue("A3", "cell value here 222");

$objPHPExcel->createSheet();
            $objPHPExcel->setActiveSheetIndex(3);
            $objPHPExcel->getActiveSheet()->setCellValue("A4", "cell value here 222");


$objPHPExcel->getActiveSheet()->setTitle('SOM');


// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="sample.pdf"');
header('Cache-Control: max-age=0');

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

 

The above code is not showing data  in second page in pdf file.

Coordinator
Nov 15, 2010 at 11:50 AM

It's a good idea to tell the Writer to write all sheets before generating the output with save()

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

 

Nov 15, 2010 at 11:53 AM

Hi MarkBaker,

It is working now thank you so much