Search code examples
phpphpexcel

PHPExcel: How to Set an a Sheet's Paper Size with a User-Defined Paper Size?


By using

$objPHPExcel->getActiveSheet() ->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4); we can set a sheet's page size, but how do you supply a custom Paper Size for this? I want to set it to 8.5' x 13.0', Letter is 8.5 x 11.0 while Legal is 8.5 x 14.0


Solution

  • Check the source code for the library you're using at https://github.com/PHPOffice/PHPExcel/blob/1.8/Classes/PHPExcel/Worksheet/PageSetup.php#L35-L100

    Line of interest is this one in the comments.

    * 14 = Folio paper (8.5 in. by 13 in.)
    

    Which you can use:

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

    It doesn't seem like you can set custom sizes though, only the predefined ones.