|
A common request from users is to be able to take the HTML-based report that is currently sitting in their browser and move it into Excel. While it's too late to help after the fact, with a little preparation, you can push that HTML table into Excel for them. |
|
|
To accomplish this feat, we take advantage of the ContentType property in the Response object. And the fact that most people have Excel on their computer. By setting the ContentType to application/vnd.ms-excel, we are instructing the browser to send the HTML output directly to Excel for processing. This nifty trick works because Excel recognizes and can load HTML output. |
|
|
<%@ Language=VBScript %> <% Response.Buffer = True Response.ContentType = "application/vnd.ms-excel" %> <table border="1"> <tr> <th>Column A</th> <th>Column B</th> <th>Totals Column</th> </tr> <tr> <td>4</td> <td>3</td> <td><font color="red">=sum(a2:b2)</font></td> </tr> <tr> <td>2</td> <td>1</td> <td><font color="red">=sum(a3:b3)</font></td> </tr> </table>
|
|
|
When this page is hit through a browser, the data will be loaded into Excel executing within the browser. Again, we assume that the user has Excel installed on their system. Also, some security settings on the browser might cause the user to be prompted to open or save the data. Only if the data is opened will Excel be loaded |
|
|
You will also notice that we are including some formatting information in the cells, as well as specifying formulae. All of this information is picked up and interpreted by Excel automatically. |
|