asp調用Word列印的代碼

來源:互聯網
上載者:User

調用Word列印...
運行下列的指令碼需要將IE的安全層級設為低,或在中級安全層級下將那個ActiveX控制項設為啟用,別忘記了:
<html>
<head>
<title>Build Document by Script</TITLE>
</HEAD>
<Table id="myData" border=1 align=center>
<Tr align=center>
<Td>產品名稱</Td>
<Td>產品描述</Td>
<Td>產品單價</Td>
<Td>產品等級</Td>
</Tr>
<Tr align=center>
<Td>產品一</Td>
<Td>This is a test</Td>
<Td align=right>300.50</Td>
<Td>一級</Td>
</Tr>
<Tr align=center>
<Td>產品二</Td>
<Td>This is a test</Td>
<Td align=right>300.50</Td>
<Td>一級</Td>
</Tr>
<Tr align=center>
<Td>產品三</Td>
<Td>This is a test</Td>
<Td align=right>300.50</Td>
<Td>一級</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("測試的表格")
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("由廖家遠設計")
objWordDoc.Application.ActiveDocument.SaveAs "tempSample.doc", 0,False,"",True,"",False,False,False, False,False
'objWordDoc.Application.printout()
End Sub
</script>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.