How to Create a Word file

Source: Internet
Author: User

How to Create a Word file

Creatdoc. asp

<! DOCTYPE html PUBLIC "-// W3C/Dtd html 3.2 Final // EN">
<Head>
<Title> galaxy shadow creates a Word file </title>
<META HTTP-EQUIV = "Refresh" CONTENT = "30; URL = 'orderform. asp '">
</Head>
<%
DotLocation = "'servernamedirectory heTemplate. dot '"
IntRowCount = Request. Form ("rowCount ")

'Initialize the row count.
%>
<Body Language = "VBScript" onLoad = "creatdoc document. theForm,
<% = DotLocation %>, intRowCount>
<Form name = "theForm">

Certificate -----------------------------------------------------------------------------------------------------------------------------------

Call onLoad in the body tag, call the creatdoc VB Script subroutine, and pass three parameters to it: the content of the form on the page (all hidden fields) the location of the Word template file and the number of lines received from the input form. read all input form fields and call the creatdoc subroutine after loading the page.
<%
ItemCount = 0

'Set the domain counter to 0.
For Each Item in Request. Form

'Total table fields.
ItemCount = itemCount + 1

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

Create a Word file object. In Internet Explorer 4 or later versions, set the security of the browser to Low or Custom.
<%
Set objWordDoc = CreateObject ("Word. Document ")
ObjWordDoc. Application. Documents. Add theTemplate, False
ObjWordDoc. Application. Visible = True
%>
Certificate -------------------------------------------------------------------------------------------------------------------------------------

Adjust the dimension of the array to make it the same as the number of rows contained in the webpage form. Set the Y axis to four constants, which are 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) %>
Certificate -------------------------------------------------------------------------------------------------------------------------------------

Start to check all form rows. collect the domain names of each form and their corresponding values in a loop of all input webpage form fields. check them one by one and put them into the corresponding columns. here, we use CASE selection for uncertain Encoding
<%
For intCount = 0 to frmData. fieldCount. value
StrOkay = "Y"
StrSearch = frmData. elements (intCount). name

'Load form domain name.
StrValue = frmData. elements (intCount). value

'Load the form field value.
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.
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
%>

Certificate -------------------------------------------------------------------------------------------------------------------------------------

Start File Creation
<%
Set rngCurrent = objWordDoc. Application. ActiveDocument. Content

'For the active file, use the variable rngCurrent to set the RANGE of the Word file object. This is to prevent the user from opening another file.
Set tabCurrent = ObjWordDoc. Application. ActiveDocument. Tables. Add
RngCurrent, intNumrows, 4)

'Determine the table size by specifying the table location (rngCurrent) and the number of rows and columns.

%>

Certificate ------------------------------------------------------------------------------------------------------------------------------------
To load data in a table.

<%
For j = 1 to intTableRows
'First refers to the row (tabRow = 1) on the first line and loops by line. Insert the carriage return [Chr (10)] at the end of each line to generate blank lines between lines and increase the row 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 ))
'Use FormatCurrency to output the circle value to ensure that the $ symbol, comma, and decimal point are used.

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 (10)

ObjWordDoc. Applicatoin. ActiveDocument. Tables (1). Rows (tabRow). Cells (3 ).
Range. ParagraphFormat. alignment = 2
'Set the number of bars at ParagraphFormat. alignment = 2 to adjust the number of circles correctly.

TabRow = tabRow + 1

Next
%>

Certificate ------------------------------------------------------------------------------------------------------------------------------------
Specify the template location and end the subroutine
<%
ObjWordDoc. Application. ActiveDocument. Paragraph. Add. Range.
InsertAfter ("Thank you for shopping at 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: For more exciting tutorials, please follow the help houseGraphic tutorialChannel,

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.