developer
developer

Reputation: 5478

Php code to convert .xml to .xls(Basically from xmlExcel to Excel spreadsheet)

Is there a way to convert .xml file to .xls using php code?

Upvotes: 0

Views: 3689

Answers (2)

John Conde
John Conde

Reputation: 219814

1) Read in the XML file using [simplexml_load_file()][1]

2) Loop through each XML element representing one line item in the XLS file

3) Use [fputcsv()][2] to create a comma separated file with the data from step 2

4) Save the file with a .csv extension and it will open in excel.

If you want to create an Excel spreadsheet I think you need to work with COM objects. Not my forté so I can't help you with that.

Upvotes: 3

Richard JP Le Guen
Richard JP Le Guen

Reputation: 28753

Dunno about converting XML to XSL, but in the book PHP Hacks there is a hack for generating excel spreadsheets most of which is available on Google Books, in its chapter on XML no less!

So that would be a good place to start looking if nobody's got the answer here.

Upvotes: 2

Related Questions