Word| creation with the increasing interest in database and Dynamic HTML (DHTML) and XML, it is becoming more and more common to use dynamic content in the data of commercial web sites. Here we have successfully used a new technique--Create Word files with ASP, I think you will be greatly inspired by the look.
Original source: http://www.asptoday.com/articles/19990825.htm
Background
Builddoc.asp is an ASP file that reads the output of a Web page form and creates a Microsoft Word file as an output that contains a table based on changes in the data in the form. The content of the form is no longer limited to static information. That is, the content displayed in the form may change as the user interacts.
The business requirement for Builddoc is to create a form letter based on the record of the Sales person's page list. Only data that has been modified by the salesperson is sent to Word, where the data is formatted into the table.
Builddoc reads all the information on the form, identifies the changed rows, and then creates a Microsoft Word file with the information contained in the changed row. Builddoc uses a template file (Builddoc.dot) that contains the address header and some preformatted text. It then writes a table to the file, each of which corresponds to a row that has been modified in the Web page's form.
How do you do it?
At the beginning, all of the page form fields are read into the hidden form field of the received Web page. In the following source code, notice the call to "OnLoad" in the body tag. It calls the Builddoc VB Script program, passing it 3 parameters: the contents of the form in the page (all suppressed fields), the location of the Word template file, the number of rows received from the input form. Read all the input form fields, and then call the Builddoc subroutine when the page is loaded. For brevity, it is assumed that all variables are declared before they are used:
The code for loading input form fields in Builddoc.asp is as follows:
〈! DOCTYPE HTML PUBLIC "-//w3c/dtd HTML 3.2 final//en" >
〈head>
〈title>build document〈/title>
〈meta http-equiv= "Refresh" content= "30; Url= ' orderform.asp ' ">
〈/head>
〈%
Dotlocation= "' Servernamedirectory Hetemplate.dot '"
Introwcount = Request.Form ("rowcount") ' Initialize a row counter
%>
〈body language= "VBScript" onload= "Builddoc Document.theform,
〈%=dotlocation%>,introwcount>
〈form name= "Theform" >
〈%
ItemCount = 0 ' Set field counter to zero
For each Item in Request.Form ' Count up the Form fields
ItemCount = itemCount + 1 ' using for.. Next Loop
%>
〈input type= "hidden" name= "〈%=item%>" value= "〈%=request (Item)%>" >
〈% Next%>
〈input type= "hidden" name= "Numbrows" value= "〈%=introwcount%>" >
〈input type= "hidden" name= "FieldCount" value= "〈%=itemcount%>" >
〈/form>
〈/body>
〈/html>
Use the code in the following example to create a Word file object. Note that in Internet Explorer 4+, the security of the browser is set to low or Custom to enable the application to run successfully.
〈%
Set Objworddoc = CreateObject ("Word.Document")
ObjWordDoc.Application.Documents.Add Thetemplate, False
Objworddoc.application.visible=true
%>
Adjusts the dimensions of the array so that it is the same number of rows as the Web page form contains. At this point, set the Y-axis to 4 constants, which is the number of columns required in the output file. The x axis contains the number of rows received from the form.
〈% Redim Preserve thearray (4,inttablerows)%>
Now start checking all the form lines. Loop through all the entered page form fields, collecting each form's domain name and its corresponding value. Check each to decide which sequence element to put into it, and then put it in. The Select Case command in the following example code is important, which determines which column the form field belongs to. For convenience, use an indeterminate code for case selection.
〈%
For intcount = 0 to FrmData.fieldCount.value
Strokay = "Y"
Strsearch = frmdata.elements (intcount). Name ' Load ' field name
strvalue = frmdata.elements (intcount). Value ' Load the field value
Strposition = Instr (1,strsearch, "_") ' Get pos val ' _ '
Intstringlen=strposition-1
If Intstrlen > 0 Then
Strleft = Left (Strsearch,intstringlen)
Strright = Right (Strsearch, (Len (Strsearch)-len (strleft)-1))
Select Case Strleft
Case "SKU" intarrayy=0
Case "description" Intarrayy=1
Case "Price" intarrayy=2
Case "quantity&