How to format an Excel workbook while streaming MIME content

This article demonstrates how you can use Active Server Pages (ASP) to create a formatted workbook that can be streamed as MIME content to Microsoft Excel.


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/"
<HTML xmlns:x="urn:schemas-microsoft-com:office:excel">
     {mso-header-data:"&CMultiplication Table\000ADate\: &D\000APage &P";

  <!--[if gte mso 9]><xml>
      <x:Name>Sample Workbook</x:Name>
   ' 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"">"
         Response.Write "    <TD bgcolor=""#B0C4DE"">"
       end if
           Response.Write CStr(i*j) + "</TD>" + vbCrLf
     Response.Write "  </TR>" + vbCrLf
  ' The user hasn't loaded the page yet. Prompt them for
  ' values for the table.
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/>
  end if

2. Save the file as XLMime.asp in the virtual root directory of your web server. (The default virtual root is C:\Inetpub\Wwwroot.)
3. Start Internet Explorer and browse to http://YourWebServer/xlmime.asp, where YourWebServer is the name of your Web server.
4. 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.

For more information on Office Automation, visit the Microsoft Office Development support site: (

  Microsoft Office Excel 2007
  Microsoft Office Excel 2003
  Microsoft Excel 2000 Standard Edition
  Microsoft Active Server Pages 4.0


Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
Microsoft Corporation. All rights reserved. Terms of Use | Trademarks


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply

To prove that you're not a bot, enter this code
Anti-Spam Image