Microsoft KB Archive/271572

= How to format an Excel workbook while streaming MIME content =

Article ID: 271572

Article Last Modified on 8/14/2007

-

APPLIES TO


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

-



This article was previously published under Q271572



SUMMARY
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.



MORE INFORMATION
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 &quot;round trip&quot;) 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 &quot;Microsoft Office HTML and XML Reference&quot; at the following MSDN Web site:

http://msdn2.microsoft.com/en-us/library/Aa155477(office.10).aspx

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(&quot;i&quot;)) = &quot;&quot; then bFirst = true ' If we have a value for &quot;i&quot;, 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 = &quot;application/vnd.ms-excel&quot; %>       <% else ' The user hasn't loaded the page yet. Prompt them for ' values for the table. %>   Please enter indices for the multiplication table:  i = <BR> j = <INPUT type=&quot;text&quot; name=j style=&quot;WIDTH: 25px&quot;><BR><BR/> <INPUT type=&quot;submit&quot; value=&quot;Submit&quot;><BR/> </FORM> </BODY> </HTML> <% end if %> </li> <li>Save the file as XLMime.asp in the virtual root directory of your web server. (The default virtual root is C:\Inetpub\Wwwroot.)</li> <li>Start Internet Explorer and browse to http://YourWebServer/xlmime.asp, where YourWebServer is the name of your Web server.</li> <li>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.</li></ol>

<div class="references_section">