Wednesday 15 August 2012

PHPExcel setting up the pages in a Workbook to print easily

Tomorrow morning I need to visit the client and help set things up so that they can easily print the pages from a Workbook .  Here are some notes taken from PHPExcel Cheat Sheet

How to add pagebreak view with PHPExcel
$objPHPExcel>setBreak('A4', PHPExcel_Worksheet::BREAK_ROW);

how to use $objPHPExcel>setBreak to make the page A4 sized

how to set orientation in PHPExcel
$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation


Setting printing breaks on a row or column

To set a print break, use the following code, which sets a row break on row 10.

$objPHPExcel->getActiveSheet()->setBreak( 'A10' , PHPExcel_Worksheet::BREAK_ROW );

The following line of code sets a print break on column D:

$objPHPExcel->getActiveSheet()->setBreak( 'D10' , PHPExcel_Worksheet::BREAK_COLUMN );


Setting a worksheet’s page orientation and size

Setting a worksheet’s page orientation and size can be done using the following lines of code:

$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);

$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);

Note that there are additional page settings available. Please refer to the API documentation for all possible options.

After visiting the office it seemed that the main thing that needed doing was to scale to fit the page.

The code I used here is .

     $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
                            $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
                            $objPHPExcel->getActiveSheet()->getPageSetup()->setFitToPage(true);


the one thing you need to watch out for here is the the object for Active Sheet has been created.  So therefore put the above code under this code.

 $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

and all will be good.

No comments: