Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- If you read the documentation, particularly the section entitled "Setting printer options for Excel files", there's a lot of information about page setup for printing:-
- Orientation and Paper Size:
- $objPHPExcel->getActiveSheet()
- ->getPageSetup()
- ->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
- $objPHPExcel->getActiveSheet()
- ->getPageSetup()
- ->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
- Page margins:
- $objPHPExcel->getActiveSheet()
- ->getPageMargins()->setTop(1);
- $objPHPExcel->getActiveSheet()
- ->getPageMargins()->setRight(0.75);
- $objPHPExcel->getActiveSheet()
- ->getPageMargins()->setLeft(0.75);
- $objPHPExcel->getActiveSheet()
- ->getPageMargins()->setBottom(1);
- Headers and Footers:
- $objPHPExcel->getActiveSheet()
- ->getHeaderFooter()
- ->setOddHeader('&C&HPlease treat this document as confidential!');
- $objPHPExcel->getActiveSheet()
- ->getHeaderFooter()
- ->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() .
- Printer page breaks:
- $objPHPExcel->getActiveSheet()
- ->setBreak( 'A10' , PHPExcel_Worksheet::BREAK_ROW );
- Showing grid lines:
- $objPHPExcel->getActiveSheet()
- ->setShowGridlines(true);
- Setting rows/columns to repeat at the top/left of each page
- $objPHPExcel->getActiveSheet()
- ->getPageSetup()
- ->setRowsToRepeatAtTopByStartAndEnd(1, 5);
- Setting the print area:
- $objPHPExcel->getActiveSheet()
- ->getPageSetup()
- ->setPrintArea('A1:E5,G4:M20');
- We write the documentation so that you don't have to ask questions like this
- 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.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement