TablePrint函数有两个参数,一个是页面Table的ID,一个是报表的标题,都是字符串变量。如:
1 | 2 |
3 | 4 |
要打印该表格只需在页面调用VBS函数TablePrint("table1","TABLE导出EXCEL测试")即可调用EXCEL控件进行报表输出。
在打印前请把客户端浏览器-Internet选项->安全 中的ActiveX部分,把禁止的都改为允许或提示即可
sub TablePrint(ByVal cTable,ByVal cTitle)
dim app
set app = createobject("Excel.Application")
app.Visible = true
dim wb
set wb=app.Workbooks.Add()
dim ws
set ws=wb.sheets(1)
dim i,i2,k
i=0
i2=0
k=0
ws.Cells.NumberFormatLocal = "@" '设置所有单元格的格式为文本
dim pt
set pt=document.all(cTable)
dim colCount
colCount = pt.rows(0).cells.length
dim Title
set Title = ws.Cells(1,6)
Title.Font.FontStyle = "加粗"
Title.Font.Size = 23
Title.value = cTitle
for k=0 to pt.rows.length-1
If pt.rows(k).Cells(1).innerText <> "" Or pt.rows(k).Cells(2).innerText <> "" Then
i2 = 0
for i=1 to colCount -1
If pt.rows(k).cells(i).style.display <> "none" Then
'if k=0 then ws.Cells(k+2,i2+1).Font.FontStyle = "加粗"
ws.Cells(k+2,i2+1).value = pt.rows(k).cells(i).innerText
i2 = i2+1
End If
Next
End If
next
end Sub
更多信息请查看IT技术专栏