asp调用Word打印的代码

2018-09-06 10:54

阅读:498

  调用Word打印...
运行下列的脚本需要将IE的安全级别设为低,或在中级安全级别下将那个ActiveX控件设为启用,别忘记了:
<html>
<head>
<title>BuildDocumentbyScript</TITLE>
</HEAD>
<Tableid=myDataborder=1align=center>
<Tralign=center>
<Td>产品名称</Td>
<Td>产品描述</Td>
<Td>产品单价</Td>
<Td>产品等级</Td>
</Tr>
<Tralign=center>
<Td>产品一</Td>
<Td>Thisisatest</Td>
<Tdalign=right>300.50</Td>
<Td>一级</Td>
</Tr>
<Tralign=center>
<Td>产品二</Td>
<Td>Thisisatest</Td>
<Tdalign=right>300.50</Td>
<Td>一级</Td>
</Tr>
<Tralign=center>
<Td>产品三</Td>
<Td>Thisisatest</Td>
<Tdalign=right>300.50</Td>
<Td>一级</Td>
</Tr>
</Tabld>
<inputtype=buttononclick=vbscript:buildDoc,4value=build>
<BODY>
</BODY>
</HTML>
<scriptlanguage=vbscript>
SubbuildDoc(theTemplate,intTableRows)
DimTable1
setTable1=document.all.myData
row=Table1.rows.length
SetobjWordDoc=CreateObject(Word.Document)
ObjWordDoc.Application.Visible=True
DimtheArray(4,4)
RedimPreservetheArray(4,row)
colnum=Table1.rows(1).cells.length
fori=0torow-1
forj=0tocolnum-1
next
next
intNumrows=4
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore(测试的表格)
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore()
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore()
SetrngPara=objWordDoc.Application.ActiveDocument.Paragraphs(1).Range
WithrngPara
.Bold=True
.ParagraphFormat.Alignment=1
.Font.Size=12
EndWith
SetrngCurrent=objWordDoc.Application.ActiveDocument.Paragraphs(3).Range
SettabCurrent=ObjWordDoc.Application.ActiveDocument.Tables.Add(rngCurrent,intNumrows,4)
fori=1tocolnum
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.InsertAftertheArray(i,1)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.ParagraphFormat.alignment=1
next
tabRow=2
Forj=2tointNumrows
ObjWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Borders.Enable=False
objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(1).Range.InsertAftertheArray(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.InsertAftertheArray(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.InsertAfterFormatCurrency(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.InsertAftertheArray(4,j)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(tabRow).Cells(4).Range.InsertAfterChr(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(DarylB.Morticum)
objWordDoc.Application.ActiveDocument.Paragraph.Add.Range.InsertAfter(SalesAssociate)
objWordDoc.Application.ActiveDocument.Envelope.InsertAddress
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertAfter(由廖家远设计)
objWordDoc.Application.ActiveDocument.SaveAstempSample.doc,0,False,,True,,False,False,False,False,False
objWordDoc.Application.printout()
EndSub
</script>


评论


亲,登录后才可以留言!