asp调用Word打印的代码_ASP教程-查字典教程网
asp调用Word打印的代码
asp调用Word打印的代码
发布时间:2016-12-29 来源:查字典编辑
摘要:调用Word打印...运行下列的脚本需要将IE的安全级别设为低,或在中级安全级别下将那个ActiveX控件设为启用,别忘记了:BuildDo...

调用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>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新ASP教程学习
    热门ASP教程学习
    编程开发子分类