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 generating Microsoft Excel worksheets on a server is (the example is in ASP, but it could be any server side technology)
Response.ContentType = "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>
You can even use style sheet statements to change border styles, background colours, etc.

