开发者

Creating Excel spreadsheet on the fly with PHP

开发者 https://www.devze.com 2022-12-22 05:45 出处:网络
I\'m creating Excel files in a PHP project. Those files aren\'t just CSV data... They are multiple tabs spreadsheets with functions and formatting.

I'm creating Excel files in a PHP project. Those files aren't just CSV data... They are multiple tabs spreadsheets with functions and formatting.

So far I'm using the Spreadsheet_Excel_Writer class that is provided with Pear.

Everything is fine but our users don't like 2 things:

  1. When they open those files generated by PHP, modify them with Exce开发者_JS百科l and save those changes, Excel ask to upgrade the file format because it was saved to version 5.0/95.
  2. Files are way too large because of the embedded images. As far as I know the only way to add images with Spreadsheet_Excel_Writer is with insertBitmap which add 24 bit bitmaps to the document.

I would like to address those issues. I'm pretty sure #1 can't be done as you can see there. But is there a way to add compressed images (jpeg) to the document?

If it's not possible to modify Spreadsheet_Excel_Writer to meet my needs, what are your class recommendations for this? Searching questions here leaded me to PHPExcel. Are there any other good alternatives out there?

If possible I would like to stick with Spreadsheet_Excel_Writer because changing to another class would be much more work (those generated spreadsheets are quite complex).

I'm using PHP 5.2.9.


I ended up using PHPExcel. With this class I can avoid point #1 since I can save in may formats (including Excel 2003/2007). For point #2 it's possible and PHPExcel do this already. When you chose the old Excel format, PHPExcel extends Spreadsheet_Excel_Writer in order to save the file.

It was a pain to rewrite my the code to use the new class but it was worth it since PHPExcel is really nice.


I've done this with PHP using XML for the spreadsheets. Check out this link for the XML spreadsheet: http://msdn.microsoft.com/en-us/library/aa140066(office.10).aspx and http://blogs.msdn.com/dmahugh/archive/2006/12/10/images-in-open-xml-documents.aspx for inserting images.

0

精彩评论

暂无评论...
验证码 换一张
取 消