分享

通过VBScript调用EXCEL生成报表进行打印的通用函数

 昵称2590559 2010-08-06

TABLE导出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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多