ASP打印Word代码
来源: 阅读:1609 次 日期:2014-09-09 11:44:25
温馨提示: 小编为您整理了“ASP打印Word代码”,方便广大网友查阅!

//保证可以运行js的情况下

<html>

<head>

<title>Build Document by Script</TITLE>

</HEAD>

<Table id="myData" border=1 align=center>

<Tr align=center>

<Td>列表1</Td>

<Td>列表2</Td>

<Td>列表3</Td>

</Tr>

<Tr align=center>

<Td>产品一</Td>

<Td>This is a test</Td>

<Td align=right>300.50</Td>

</Tr>

<Tr align=center>

<Td>产品二</Td>

<Td>This is a test</Td>

<Td align=right>300.50</Td>

</Tr>

<Tr align=center>

<Td>产品三</Td>

<Td>This is a test</Td>

<Td align=right>300.50</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>

更多信息请查看IT技术专栏

更多信息请查看脚本栏目
手机网站地址:ASP打印Word代码
由于各方面情况的不断调整与变化, 提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!

2025国考·省考课程试听报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:
咨询QQ:526150442(9:00—18:00)版权所有:
云南网警报警专用图标
Baidu
map