Excel can persist storage information in a format that
is an HTML/XML hybrid. When you save an Excel 2000 workbook as a Web page,
Excel creates a file that contains a combination of HTML tags and XML tags that
have special meaning to Excel. A workbook saved in this format can go from
Excel to the browser and back to Excel again (a "round trip") without losing
workbook integrity.
When you open a workbook saved as a Web page in
Internet Explorer, the HTML tags are used to render the document. When you open
a workbook in this format in Excel, Excel uses the XML tags for settings that
might pertain to the workbook, worksheets, rows and columns. For more
information on using HTML and XML with Excel 2000, see "Microsoft Office HTML
and XML Reference" at the following MSDN Web site:
Using ASP, you can create your own documents in Excel's HTML/XML
format so that when the document is streamed to the client browser, it is
displayed in Excel. You can control the cell placement of data and specify any
workbook or worksheet settings that are supported by Excel's HTML/XML format.
To create an Excel workbook in the HTML/XML format and then stream it as MIME
content to Excel on the client, follow these steps:
- Paste the following code into Notepad:
<%@ Language=VBScript %>
<%
' Check for a value passed on the address bar.
if (Request.QueryString("i")) = "" then bFirst = true
' If we have a value for "i", we know that we can display the
' data in Excel.
if (bFirst = false) then
' Buffer the content and send it to Excel.
Response.Buffer = true
Response.ContentType = "application/vnd.ms-excel"
%>
<HTML xmlns:x="urn:schemas-microsoft-com:office:excel">
<HEAD>
<style>
<!--table
@page
{mso-header-data:"&CMultiplication Table\000ADate\: &D\000APage &P";
mso-page-orientation:landscape;}
br
{mso-data-placement:same-cell;}
-->
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sample Workbook</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml><![endif]-->
</HEAD>
<BODY>
<TABLE>
<%
' Build a multiplication table from 1,1 to i,j.
for i = 1 to CInt(Request.QueryString("i"))
Response.Write " <TR>" + vbCrLf
for j = 1 to CInt(Request.QueryString("j"))
if (j = 1) or (i = 1) then
Response.Write " <TD bgcolor=""#FFF8DC"">"
else
Response.Write " <TD bgcolor=""#B0C4DE"">"
end if
Response.Write CStr(i*j) + "</TD>" + vbCrLf
next
Response.Write " </TR>" + vbCrLf
next
%>
</TABLE>
</BODY>
</HTML>
<%
else
' The user hasn't loaded the page yet. Prompt them for
' values for the table.
%>
<HTML>
<BODY>
Please enter indices for the multiplication table:<BR>
<FORM action="xlmime.asp" method=GET>
i = <INPUT type="text" name=i style="WIDTH: 25px"><BR>
j = <INPUT type="text" name=j style="WIDTH: 25px"><BR><BR/>
<INPUT type="submit" value="Submit"><BR/>
</FORM>
</BODY>
</HTML>
<%
end if
%>
- Save the file as XLMime.asp in the virtual root directory
of your web server. (The default virtual root is
C:\Inetpub\Wwwroot.)
- Start Internet Explorer and browse to http://YourWebServer/xlmime.asp, where YourWebServer is the name of your Web server.
- In the Web page that appears, supply numeric values in each
of the text boxes provided and then click Submit. Excel in-place activates in the browser with a new workbook. The
new workbook contains formatted data in the number of rows (i) and the number
of columns (j) that you specified. Also, if you check the Page Setup
information for the worksheet, you will notice that the orientation is set to
landscape and that a custom header exists.