Advertisement
krot

phpExcel

Jun 30th, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.58 KB | None | 0 0
  1. 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:-
  2.  
  3. Orientation and Paper Size:
  4.  
  5. $objPHPExcel->getActiveSheet()
  6.    ->getPageSetup()
  7.    ->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
  8. $objPHPExcel->getActiveSheet()
  9.    ->getPageSetup()
  10.    ->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
  11.  
  12. Page margins:
  13.  
  14. $objPHPExcel->getActiveSheet()
  15.    ->getPageMargins()->setTop(1);
  16. $objPHPExcel->getActiveSheet()
  17.    ->getPageMargins()->setRight(0.75);
  18. $objPHPExcel->getActiveSheet()
  19.    ->getPageMargins()->setLeft(0.75);
  20. $objPHPExcel->getActiveSheet()
  21.    ->getPageMargins()->setBottom(1);
  22.  
  23. Headers and Footers:
  24.  
  25. $objPHPExcel->getActiveSheet()
  26.    ->getHeaderFooter()
  27.    ->setOddHeader('&C&HPlease treat this document as confidential!');
  28. $objPHPExcel->getActiveSheet()
  29.    ->getHeaderFooter()
  30.    ->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() .
  31.  
  32. Printer page breaks:
  33.  
  34. $objPHPExcel->getActiveSheet()
  35.    ->setBreak( 'A10' , PHPExcel_Worksheet::BREAK_ROW );
  36.  
  37. Showing grid lines:
  38.  
  39. $objPHPExcel->getActiveSheet()
  40.    ->setShowGridlines(true);
  41.  
  42. Setting rows/columns to repeat at the top/left of each page
  43.  
  44. $objPHPExcel->getActiveSheet()
  45.    ->getPageSetup()
  46.    ->setRowsToRepeatAtTopByStartAndEnd(1, 5);
  47.  
  48. Setting the print area:
  49.  
  50. $objPHPExcel->getActiveSheet()
  51.    ->getPageSetup()
  52.    ->setPrintArea('A1:E5,G4:M20');
  53.  
  54. We write the documentation so that you don't have to ask questions like this
  55.  
  56.  
  57. 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
  58.  
  59. How to add pagebreak view with PHPExcel
  60. $objPHPExcel>setBreak('A4', PHPExcel_Worksheet::BREAK_ROW);
  61.  
  62. how to use $objPHPExcel>setBreak to make the page A4 sized
  63.  
  64. how to set orientation in PHPExcel
  65. $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation
  66.  
  67.  
  68. Setting printing breaks on a row or column
  69.  
  70. To set a print break, use the following code, which sets a row break on row 10.
  71.  
  72. $objPHPExcel->getActiveSheet()->setBreak( 'A10' , PHPExcel_Worksheet::BREAK_ROW );
  73.  
  74. The following line of code sets a print break on column D:
  75.  
  76. $objPHPExcel->getActiveSheet()->setBreak( 'D10' , PHPExcel_Worksheet::BREAK_COLUMN );
  77.  
  78.  
  79. Setting a worksheet’s page orientation and size
  80.  
  81. Setting a worksheet’s page orientation and size can be done using the following lines of code:
  82.  
  83. $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
  84.  
  85. $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
  86.  
  87. Note that there are additional page settings available. Please refer to the API documentation for all possible options.
  88.  
  89. After visiting the office it seemed that the main thing that needed doing was to scale to fit the page.
  90.  
  91. The code I used here is .
  92.  
  93.      $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
  94.                             $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
  95.                             $objPHPExcel->getActiveSheet()->getPageSetup()->setFitToPage(true);
  96.  
  97. 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.
  98.  
  99.  $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
  100.  
  101. and all will be good.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement