Web Hosting Talk







View Full Version : import xml to excel


orbitz
04-14-2006, 10:18 AM
Hello,

I k now that we can create csv file from PHP and import the file to excel. However, csv file is just a plain text file, and when importing it to excel, the spreadsheet has no format such as bold, italic, or hightlighted cells.

I was thinking if we can use PHP to create xml with some format for some cells to have them either highlighted, bold, or other type of formats. Then, when we import this xml file to Excel, those cells will have the format - highlighted, bold, or other in the Excel spreadsheet?

Thanks!

nnormal
04-14-2006, 10:30 AM
You can get xl to open html by simply renaming it to a .xls in the header. It doesnt play very well with css though so you have to use old school styling:



<?
header('Content-type: application/xls');
header('Content-Disposition: attachment; filename="fake.xls"');
?>
<html>
<table border="1">
<tr>
<td bgcolor="silver"><b>header1</b></td>
<td bgcolor="silver"><b>header2</b></td>
<td bgcolor="silver"><b>header3</b></td>
</tr>
<tr>
<td>1</td>
<td><i>not available</i></td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td><i>not available</i></td>
<td>2</td>
<td>3</td>
</tr>
</table>
</html>

orbitz
04-14-2006, 10:43 AM
Perfect solution - tested and worked great!

thanks a lot nnormal!