Create excel file using PHP compatible for 2007 and 2003
am creating a .xls file using PHP fopen
write and append the contents to the file. Works fine with Excel 2003.
But excel 2007 showing a alert before opening as un supported type.
If i create file with .xlsx extension 开发者_如何学Python, it is not opening in 2003.
Is there any standard way that works fine in both 2003 and 2007 versions .
Use PHPExcel. It's free and can read/write Excel 03/07 files directly. There's Spreadsheet_Excel_Writer in the PEAR library, but it's essentially dead and only support writing BIFF5 files, which corresponds to Excel '95 ('97? not sure...)
What format are you actually writing? Writing an Excel file isn't simply a matter of giving an arbitrary file an extension of xlsx or xls.
For commonality, you can write a BIFF5 or BIFF8 xls file (all versions of Excel post 95 will read this), or there is the Excel 2003 XML format, which can be opened by both Excel 2003 and Excel2007 (and Excel 2010 as well).
If you don't need any formatting or even multiple sheets the easiest thing to do is to just create a comma-separated file. (.csv) 2003 and 2007 can open those just fine. It's also much easier to deal with in PHP
I bet he wants to to the same thing I want: create a tab-delimited file (instead of comma-delimited), to avoid dealing with apostrophes or commas with the cells. Just $field_contents . "\t" . $next_field_contents
We know that if we create a comma-delimited file with extension CSV the browser will send it to Excel (somehow). What I want (and the questioner probably wants) is a way to:
- produce a TAB-delimited file
- have the browser tell the operating system to have Excel open it
- (but not ask the user any questions, e.g., about formatting)
Those who do not know how to do this, please shush! But if anyone knows whether this is possible or not, please speak up!!!!
精彩评论