views:

38

answers:

3

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 , it is not opening in 2003.

Is there any standard way that works fine in both 2003 and 2007 versions .

A: 

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

Cfreak
not what he asked for, but right! As long as you don't need to generate complex XLS Files (including different sheets and other meta stuff) CSV is the way to go, still, I guess that would had made more sense as a comment
Hannes
actually am writing tab seperated files to .xls files. This is not pure xls i know. Then how can i write content to a pure xls file?
zod
Just saving it as .XLS doesn't make it .XLS ... I'm surprised it works at all. If you change the extension to .csv (even with tab separated) it should import in 2007
Cfreak
A: 

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).

Mark Baker
am creating a .xls file, write the contents to the file as \t tab seperated.
zod
@zod - No, you're not creating an xls file, you're creating a tab-delimited file... don't give it an xls extension: Excel 2007 is basically telling you that you're lying to it, that what you're claiming is an xls file is no such thing. Try writing as comma-separated value rather than tab-separated, and giving it an extension of .csv (Excel should open this without issue), or create a real xls BIFF5 or BIFF8 file.
Mark Baker
yea . that is the only way i have now.
zod
@zod - Creating a CSV file is easier if you don't need formatting or multiple worksheets, or any of the other special features of Excel: if you do need any of those extras, then there is still the option of creating a real MS Excel file using one of the available PHP libraries for Excel
Mark Baker
+1  A: 

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...)

Marc B
@Marc - For future reference, BIFF5 is Excel5/95, BIFF8 is Excel97/2003
Mark Baker