标题 | 通过VBScript调用EXCEL生成报表进行打印的通用函数 |
内容 | TablePrint函数有两个参数,一个是页面Table的ID,一个是报表的标题,都是字符串变量。如: <table id="table1" > <tr> <td></td>1<td>2</td> </tr> <tr> <td></td>3<td>4</td> </tr> </table> 要打印该表格只需在页面调用VBS函数TablePrint("table1","TABLE导出EXCEL测试")即可调用EXCEL控件进行报表输出。 在打印前请把客户端浏览器-Internet选项->安全 中的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 = "@" '设置所有单元格的格式为文本 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 |
随便看 |
|
在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。