Serving an Excel Worksheet to a browser.

By fritz

Writing an excel worksheet to a browser is pretty simple – all you need is the correct response type, and to format the data using an HTML table.

The response type for generatig Microsoft Excel worksheets on a server is, in ASP:

Response.ContentType = "application/vnd.ms-excel"

and in PHP

header('Content-type: application/vnd.ms-excel');

After that, write a simple table (without HTML head), and Excel will convert it to a worksheet. You can use formulas etc:

<%Response.ContentType = "application/vnd.ms-excel"%>
<table border="1">
<tr>
  <th>Name</th>
  <th>Cost</th>
</tr>
<tr>
  <td>John</td>
  <td>34</td>
</tr>
<tr>
  <td>Marl</td>
  <td>122</td>
</tr>
<tr>
  <th>TOTAL</th>
  <td>=SUM(B2:B3)</td>
</tr>
</table>

Leave a Reply