Create an Excel fileTag(s): IO


While you can use specialized packages to create native Excel file, an easy way to import data into Excel is to create an HTML file and embed the date into a TABLE tag. You give to the file the XLS extension and Excel will do the translation for you!

With a text editor or from a program, create a file named test.xls with this content

<TABLE> 
<th><h4>Just testing</h4>
<TR><TD width="20">1</TD><TD width="30">2</TD><TD width="40">3</TD></TR>
<TR><TD>4</TD><TD>4</TD><TD>6</TD></TR>
<TR><TD>7</TD><TD>8</TD><TD>9</TD></TR>
<TR><TD>=SUM(A3:A5)</TD><TD>=SUM(B3:B5)</TD><TD>=SUM(C3:C5)</TD></TR>
</TABLE>

Now you can double click on the saved file to load it into Excel and the translation will be done.

This trick works with OpenOffice too.

From a server, remember to send the appropriate MIME TYPE : application/excel to the client.

See also this HowTo


blog comments powered by Disqus