asp调用Word打印的代码

时间:2021-05-28

调用Word打印...
运行下列的脚本需要将IE的安全级别设为低,或在中级安全级别下将那个ActiveX控件设为启用,别忘记了:
<html>
<head>
<title>BuildDocumentbyScript</TITLE>
</HEAD>
<Tableid="myData"border=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'',4"value="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
theArray(j+1,i+1)=Table1.rows(i).cells(j).innerHTML
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.Name="Arial"
.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.SaveAs"tempSample.doc",0,False,"",True,"",False,False,False,False,False
'objWordDoc.Application.printout()
EndSub
</script>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章