โทรหา 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> ผลิตภัณฑ์ 1 </td>
<td> Thisisastest </td>
<tdalign = ขวา> 300.50 </td>
<td> ระดับ 1 </td>
</tr>
<tralign = center>
<td> ผลิตภัณฑ์ 2 </td>
<td> Thisisastest </td>
<tdalign = ขวา> 300.50 </td>
<td> ระดับ 1 </td>
</tr>
<tralign = center>
<td> ผลิตภัณฑ์ 3 </td>
<td> Thisisastest </td>
<tdalign = ขวา> 300.50 </td>
<td> ระดับ 1 </td>
</tr>
</tabld>
<inputType = buttonOnclick = "vbscript: buildDoc '', 4" value = "build">
<body>
</body>
</html>
<scriptLanguage = "vbscript">
SubbuildDoc (TheTeMplate, IntTableRows)
dimtable1
Settable1 = document.all.mydata
แถว = table1.rows.length
setObjworddoc = createObject ("word.document")
objworddoc.application.visible = true
Dimthearray (4,4)
'redimpreserveThearray (4, แถว)
colnum = table1.rows (1) .cells.length
fori = 0torow-1
forj = 0tocolnum-1
thearray (j+1, i+1) = table1.rows (i) .cells (j) .innerhtml
ต่อไป
ต่อไป
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).
withrngpara
.bold = จริง
.paragraphformat.Alignment = 1
.font.name = "Arial"
.Font.Size = 12
จบลงด้วย
setRngCurrent = objworddoc.application.activedocument.paragraphs (3).
SettAbCurrent = objworddoc.application.activedocument.tables.add (rngcurrent, intnumrows, 4)