TablePrint函數(shù)有兩個(gè)參數(shù),一個(gè)是頁(yè)面Table的ID,一個(gè)是報(bào)表的標(biāo)題,都是字符串變量。如:
<table id="table1" >
<tr>
<td></td>1<td>2</td>
</tr>
<tr>
<td></td>3<td>4</td>
</tr>
</table>
要打印該表格只需在頁(yè)面調(diào)用VBS函數(shù)TablePrint("table1","TABLE導(dǎo)出EXCEL測(cè)試")即可調(diào)用EXCEL控件進(jìn)行報(bào)表輸出。
在打印前請(qǐng)把客戶(hù)端瀏覽器-Internet選項(xiàng)->安全 中的ActiveX部分,把禁止的都改為允許或提示即可
<script language="VBScript">
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 = "@" '設(shè)置所有單元格的格式為文本
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
更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄