phpmpdfphpexcel-1.8.0

How to save the Printable Area on an xlsx file to a PDF with PHPExcel


How would i go about saving the printable area on an excel sheet as a PDF?

If I need to use a different lib then I can work with that, but I need it to be as close to the same look as possible as when printing from excel, I know that is hard in general.


Solution

  • On the assumption that you are working on a Windows server, I am going to suggest a different approach: using the COM or DOTNET class libraries available in PHP on Windows (http://php.net/manual/en/book.com.php). If not, please disregard my answer as it will not work.

    My idea is to use the native Excel macro capability to select the Print Area and using the built-in Export to PDF function. In this way cell formats should remain intact. So your .xlsw becomes a .xlsm file with the addition of the required VBA code to select the proper range (Print Area) and Export to a PDF. Then the COM or DOTNET class libraries would be used to instatiate the spreadsheet and access exposed objects (macros included). You might also be able to drive the export through COM/DOTNET automation and not use a macro if you do not have control over the spreadsheet itself.