You can create text-based documents for Excel by using the following formats:
- Comma-separated (.csv)
- Tab-delimited (.txt)
- XML (Excel 2002)
- Rich Text Format (.rtf)
How to Create the Script
- Start any text or HTML editor and paste the following code into the editor:
<%@ Language=VBScript %>
Dim r, Amount, Tax
'Change HTML header to specify Excel's MIME content type.
Response.Buffer = TRUE
Response.ContentType = "application/vnd.ms-excel"
<TD WIDTH="120" ALIGN="Right"><B>Amount</B></TD>
<TD WIDTH="120" ALIGN="Right"><B>Tax</B></TD>
<% For r= 1 to 20 %>
<% Amount = FormatCurrency(Rnd()*1000,2) %>
<% Tax = FormatCurrency(Amount*0.07,2) %>
<% Next %>
- Save the new script as Exceldoc.asp in the virtual root folder of your Web server. The default root is C:\Inetpub\Wwwroot.
How to Run the Script
- Start Microsoft Internet Explorer.
- In the address bar, type http://YourWebServer/ExcelDoc.asp (where YourWebServer is the name of your Web server) and press ENTER.
- After the table is opened in Excel, examine the results. Note the formatting and the formulas in cells B23 and C23.
How to Try It AgainNext, modify the script so that the the document opens in Word instead of Excel:
- In the script, modify the MIME type as follows:
Response.ContentType = "application/msword"
- Save the modified document in the virtual root folder of your Web server as Worddoc.asp.
- Start Internet Explorer and browse to http://YourWebServer/WordDoc.asp (where YourWebServer is the name of your Web server).
ToubleshootingUsing a text-based format for your Office documents can provide a solution on your Web server that is very scalable and provides good performance. A disadvantage of using text-based formats is that you are limited in the Office features that you can use. Some developers may choose to use Automation for Office document creation; although Automation in a client-side environment gives you the greatest flexibility in exploiting all the features that are available in Office, it can generate some problems for a server-side application. If you find that using a text-based document format does not deliver the level of document creation you need, you may want to see the following Knowledge Base article to determine if Automation might be a solution that is right for you:
ID articol: 301044 - Ultima examinare: 17 ian. 2007 - Revizie: 1