PHPExcel PDF Layout

So, I export the Excel file created using PHPExcel to PDF. My only problem is that the content runs across the width of the page (rather than the length), the content of which disappears. Only a blank page is created where this content should be. I tried to insert a column break with a line similar to this example from the documentation, but only line breaks seem to work with PDF:

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

It is worth mentioning that I work from a Symfony2 controller, which means a slash before listing PHPExcel.

My ideal solution is for any additional content to go to a second page, which can be placed next to the first page to show the whole table as it appears in a real Excel document.

+3
source share
2 answers

This is a limitation of the external library used by PHPExcel to render html output in PDF format (namely tcPDF).

Although I am aware of several other libraries that can create PDFs from HTML (for example, domPdf and mPdf), and future versions of PHPExcel will let you choose which of these libraries you want to use, none of them look capable of generating multiple pages for display data from the full width of the worksheet.

If anyone cannot offer an alternative, I am afraid that this will remain a limitation in the foreseeable future.

+1
source

I had a similar vertical problem, the solution I found was to use this

$highestRow = $objPHPExcel->setActiveSheetIndex(0)
    ->getHighestRow();

$objPHPExcel->setActiveSheetIndex(0)
    ->getPageSetup()
    ->setPrintArea("A1:I" . $highestRow )
    ->setFitToHeight(255);

I would suggest trying something similar in width. eg:

   $highestColumn= $objPHPExcel->setActiveSheetIndex(0)
        ->getHighestColumn();


    $objPHPExcel->setActiveSheetIndex(0)
        ->getPageSetup()
        ->setPrintArea("A1:" . $highestColumn . "10" )
        ->setFitToWidth(255);
0
source

All Articles