Microsoft small business knowledge base

Article ID: 260239 - Last Review: February 12, 2007 - Revision: 2.2

This article was previously published under Q260239


This article demonstrates how to format a field to preserve the leading digits (such as the "000" in "0001112") or a specific formula when you create an Excel file with an Active Server Pages (ASP) page.


If you set the
Response.ContentType = "application/"
in an ASP page, Excel will be launched to process the document and display it as an Excel spreadsheet. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
199841  ( ) How To Display ASP Results Using Excel in IE with MIME Types
If the table field has a leading zero, then the zero (or zeros) will be stripped because Excel treats the field as a numeric value.

You can specify the cell as a string value to preserve the format in the ASP page. You can even specify the formula for calculation in your code.

The following page, Test.asp, demonstrates how you can do this:
<%@ Language=VBScript %>
      'Change HTML header to specify Excel's MIME content type
      Response.Buffer = TRUE
      Response.ContentType = "application/"
   <!-- Our table which will be translated into an Excel spreadsheet -->
      <TD>Book ID</TD>
      <TD>Book Title</TD>
      <TD>Shipping Fee</TD>
      <TD>Tax Rate</TD>
      <TD>Total Cost</TD>
      <TD>The Perfect Programming Book</TD>


For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
247318  ( ) BUG: Word 2000 and Excel 2000 Do Not Redirect Correctly When Using Response.Redirect
264143  ( ) FIX: ASP Session Variables Empty When Office 2000 MIME Types Are Streamed with Internet Explorer

  • Microsoft Excel 2000 Service Pack 1
  • Microsoft Excel 2000 Standard Edition
  • Microsoft Internet Explorer 4.0 128-Bit Edition
  • Microsoft Internet Explorer 4.01 Service Pack 2
  • Microsoft Internet Explorer 4.01 Service Pack 1
  • Microsoft Internet Explorer 5.0
  • Microsoft Internet Explorer 5.01
  • Microsoft Internet Explorer 5.5
  • Microsoft Excel 97 Standard Edition
kbhowto kbscript KB260239
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support