Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML

Adding Persistent Excel Sheets to Your Web Page

0.00/5 (No votes)
13 Apr 2011CPOL 10.5K  
How to add a persistent Excel sheet to your web page

Adding an Excel sheet to your web page can be done by simply adding an object with a particular classid to your page, as shown below:

HTML
<table > 
<tr style="height: 500px">
<td>
<object id="spreadsheet1" width="100%" height="100%" 
   classid="clsid:0002E559-0000-0000-C000-000000000046" viewastext>
<param name="MaxHeight" value="1000px" />
<param name="MaxWidth" value="1000px" />
</object>
</td>
</tr>
</table>

This will only work on Internet Explorer, and you also need to have OWC (Office Web Component) installed on your computer. If you have Microsoft Office 2003 installed, you would already have OWC; otherwise, you can download it from here.

To make the Excel sheet persistent, you want access to its data so you can store it to the database. The object shown above is not an ASPX control that you can have access to in code-behind. The JavaScript code in your page, however, would have access to this data as:

JavaScript
document.form1.spreadsheet1.XMLData

You can use a Web Service to store or retrieve data. To access a Web Service from JavaScript, you have two options. One is using the webservice.htc component to bring Web Service behaviour to your web page as explained in About WebService Behavior. The other option is to use ASP.NET AJAX to access Web Services as outlined in Calling Web Services with ASP.NET AJAX.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)