A Simple Solution

If you only want to use a single Excel worksheet and have a relatively simple spreadsheet, then you can use this approach. We create a standard HTML table and then pass it back from our Server Side Script - in this case a VBScript Active Server Pages (ASP) script - with the MIME type of Excel and not HTML, this call is then managed by the browser.

The first thing we do in our script is to set the Content Type we are going to return to the client browser.

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

Now that we have told the browser that we are sending back an Excel file, we simply create our standard HTML table and send that back. This table could be generated from the results of a database query for example or simply a static HTML.

A demo is available, and the source code is below :

<table>
    <tr>
        <td><b>Main Header</b></td>
        <td><b>Content</b></td>
    </tr>
    <tr>
        <td>First Column, First Cell</td>
        <td>First Column, Second Cell</td>
    </tr>
    <tr>
        <td>Second Column, First Cell</td>
        <td>Second Column, Second Cell</td>
    </tr>
</table>

You are also able to include some simple Excel commands in the data for example we could create three columns, first value, second value and then a total column as follows :

<table>
    <tr>
        <td><b>First Value</b></td>
        <td><b>Second Value</b></td>
        <td><b>Total</b></td>
    </tr>
    <tr>
        <td><b>10</b></td>
        <td><b>20</b></td>
        <td><b>=Sum(A2:B2)</b></td>
    </tr>
</table>

To see this working click here. What result you get depends on how your Web Browser is set up to handle .XLS files, in some cases it will render in the web browser, in others it will open Excel and load the file in there for example. This activity is determined by the local client machine settings for MIME types and is outside the control of a webpage.

This should suffice many developers, but if you need a little more flexibility or complexity, then you will have to use an ActiveX component, as detailed in the next section.

Website Designed by Adservio Consulting      Bookmark and Share Valid HTML 4.01 Strict    Valid CSS!    Level A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0