How to create a Word file

Source: Internet
Author: User

Creatdoc.asp

<! DOCTYPE HTML PUBLIC "-//w3c/dtd HTML 3.2 final//en" >

<title> Star of the Galaxy create a Word file </title>
<meta http-equiv= "Refresh" content= "30; Url= ' orderform.asp ' ">

<%
Dotlocation= "' Servernamedirectory Hetemplate.dot '"
Introwcount = Request.Form ("RowCount")

' Initialize row count.
%>
<body language= "VBScript" onload= "Creatdoc Document.theform,
<%=dotLocation%>,intRowCount>
<form name= "Theform" >

--------------------------------------------------------------------------------------------------------------- --------------------

In the body tag to the onload call, call Creatdoc VB Script program, pass it 3 parameters: the content 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 input form fields, Then call the Creatdoc subroutine when the page is loaded
<%
ItemCount = 0

' Set the field counter to 0.
For each Item in Request.Form

' Total table field.
ItemCount = ItemCount + 1

' Use 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>
--------------------------------------------------------------------------------------------------------------- ----------------------

Starts creating a Word file object. In Internet Explorer version 4, to set the browser's security to low or Custom
<%
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. Set the y-axis to 4 constants, which is the number of columns required in the output file, and the x axis contains the number of rows received from the form
<% Redim Preserve thearray (4,inttablerows)%>
--------------------------------------------------------------------------------------------------------------- ----------------------

Start checking all of the form lines. Loops through all the entered page form fields, collecting each form's domain name and its corresponding value. Examine it one by one and place it in the corresponding sequence element. Here we use the case selection with the uncertainty code
<%
For intcount = 0 to FrmData.fieldCount.value
Strokay = "Y"
Strsearch = frmdata.elements (intcount). Name

' Mount the form domain name.
strvalue = frmdata.elements (intcount). Value

' Load form field values.
Strposition = Instr (1,strsearch, "_")

Intstringlen=strposition-1
If Intstrlen > 0 Then
Strleft = Left (Strsearch,intstringlen)
Strright = Right (Strsearch, (Len (Strsearch)-len (strleft)-1))
Select Case Strleft

The Select case command determines which column the form field belongs to.
Case "SKU" intarrayy=0
Case "description" Intarrayy=1
Case "Price" intarrayy=2
Case "Quantity" intarrayy=3
End Select
Intarrayx = Strright
If strokay <> "N" Then
TheArray (Intarrayy, intarrayx) = strvalue
End If
End If
Next
%>

--------------------------------------------------------------------------------------------------------------- ----------------------

Start creating files
<%
Set rngcurrent = objWordDoc.Application.ActiveDocument.Content

' For active files, use variable rngcurrent to set the Word file object range to prevent users from opening another file.
Set tabcurrent = ObjWordDoc.Application.ActiveDocument.Tables.Add
rngcurrent,intnumrows,4)

' determines its size by specifying the position of the table (rngcurrent) and the number of rows and columns.

%>

--------------------------------------------------------------------------------------------------------------- ---------------------
Yearning to load data into the form.

<%
for j = 1 to inttablerows
  ' first refers to the first row of row (tabrow=1), and loops by line. Inserts a carriage return [CHR (10)] at the end of each line to produce a blank row between rows, increasing the line counter.
ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (Tabrow). Borders.enable=false

ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (Tabrow). Cells (1). Range.InsertAfter
    TheArray (1,j)

ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (Tabrow). Cells (2). Range.InsertAfter
    TheArray (2,j)

ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (Tabrow). Cells (3). Range.InsertAfter
    FormatCurrency (TheArray (3,j))
     ' exports U.S. dollar value in FormatCurrency to ensure use $ symbol, comma, position of decimal point.

ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (Tabrow). Cells (4). Range.InsertAfter
    TheArray (4,j)

ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (Tabrow). Cells (4). Range.InsertAfter
    CHR (a)

ObjWordDoc.Applicatoin.ActiveDocument.Tables (1). Rows (Tabrow). Cells (3).
    range.paragraphformat.alignment=2
     '   in ParagraphFormat alignment= 2 Set the number of columns to achieve the correct number of dollars adjustment.

Tabrow = tabrow + 1

Next
%>

------------------------------------------------------------------------------------------------------------ ------------------------
Specify template location, End subroutine
<%
ObjWordDoc.Application.ActiveDocument.Paragraph.Add.Range .
    InsertAfter ("Thank for shopping in Acme Co., and please come again!")
ObjWordDoc.Application.ActiveDocument.Paragraph.Add.Range.InsertAfter ("")
ObjWordDoc.Application.ActiveDocument.Paragraph.Add.Range.InsertAfter ("")
ObjWordDoc.Application.ActiveDocument.Paragraph.Add.Range.InsertAfter ("Regards,")
ObjWordDoc.Application.ActiveDocument.Paragraph.Add.Range.InsertAfter ("")
ObjWordDoc.Application.ActiveDocument.Paragraph.Add.Range.
  InsertAfter ("Daryl B. Morticum")
ObjWordDoc.Application.ActiveDocument.Paragraph.Add.Range.
  InsertAfter ("Sales associate")
End Sub
%>

        Note : More wonderful tutorials please focus on the triple graphics and text tutorial channel,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.