ASP invoke code to print in Word _ Application Tips
Source: Internet
Author: User
Call Word print ...
Run the following script to set the security level for IE to low, or set the ActiveX control to Enabled at intermediate security levels, and don't forget:
<title>build Document by script</title>
</HEAD>
<table id= "MyData" Border=1 align=center>
<tr align=center>
<Td> Product Name </Td>
<Td> Product Description </Td>
<Td> Product Price </Td>
<Td> Product Grade </Td>
</Tr>
<tr align=center>
<Td> Product One </Td>
<td>this is a test</td>
<TD align=right>300.50</td>
<Td> level </Td>
</Tr>
<tr align=center>
<Td> Products Two </Td>
<td>this is a test</td>
<TD align=right>300.50</td>
<Td> level </Td>
</Tr>
<tr align=center>
<Td> Product Three </Td>
<td>this is a test</td>
<TD align=right>300.50</td>
<Td> level </Td>
</Tr>
</Tabld>
<input Type=button onclick= "Vbscript:builddoc ', 4" value= "Build" >
<BODY>
</BODY>
</HTML>
<script language= "VBScript" >
Sub Builddoc (thetemplate,inttablerows)
Dim Table1
Set Table1 = Document.all.myData
row = Table1.rows.length
Set Objworddoc = CreateObject ("Word.Document")
Objworddoc.application.visible=true
Dim TheArray (4,4)
' Redim Preserve thearray (4,row)
Colnum = table1.rows (1). cells.length
For I=0 to Row-1
For J=0 to Colnum-1
TheArray (j+1,i+1) = Table1.rows (i). Cells (j). InnerHTML
Next
Next
Intnumrows = 4
ObjWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore ("Test table")
ObjWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore ("")
ObjWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore ("")
Set Rngpara = objWordDoc.Application.ActiveDocument.Paragraphs (1). Range
With Rngpara
. Bold = True
. ParagraphFormat.Alignment = 1
. Font.Name = "Arial"
. Font.Size = 12
End With
Set rngcurrent = objWordDoc.Application.ActiveDocument.Paragraphs (3). Range
Set tabcurrent = OBJWORDDOC.APPLICATION.ACTIVEDOCUMENT.TABLES.ADD (rngcurrent,intnumrows,4)
For i = 1 to Colnum
ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (1). Cells (i). Range.InsertAfter TheArray (i,1)
ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (1). Cells (i). Range.paragraphformat.alignment=1
Next
Tabrow = 2
For j = 2 to Intnumrows
' 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 (1). Range.paragraphformat.alignment=1
ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (Tabrow). Cells (2). Range.InsertAfter TheArray (2,J)
ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (Tabrow). Cells (2). Range.paragraphformat.alignment=1
ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (Tabrow). Cells (3). Range.InsertAfter FormatCurrency (TheArray (3,J))
ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (Tabrow). Cells (3). range.paragraphformat.alignment=2
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.Application.ActiveDocument.Tables (1). Rows (Tabrow). Cells (4). Range.paragraphformat.alignment=1
Tabrow = Tabrow + 1
Next
' ObjWordDoc.Application.ActiveDocument.Tables (1). Rows (Tabrow). Cells (4). Range.paragraphformat.alignment=1
' 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")
' ObjWordDoc.Application.ActiveDocument.Envelope.Insert address
' ObjWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertAfter ("Designed by Liao")
ObjWordDoc.Application.ActiveDocument.SaveAs "Tempsample.doc", 0,false, "", True, "", False,false,false, False,false
' ObjWordDoc.Application.printout ()
End Sub
</script>
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