ASP导出为Word或Excel的最简单方法

来源:互联网 发布:无锡亿美网络 编辑:程序博客网 时间:2024/05/22 14:39

在ASP文件的最开头位置加入下面的代码就可以了,非常简单。
Asp代码

    EXCEL      <%      Response.ContentType ="application/vnd.ms-excel"      Response.AddHeader "Content-Disposition", "attachment; filename=表格名.xls"      %>      WORD      <%      Response.ContentType ="application/vnd.ms-word"      Response.AddHeader "Content-Disposition", "attachment; filename=文件名.doc"      %>  

导出为WORD时,若文档中含有表格,需要打打印,则要在导出的页面中加入下面的样式。
Css代码

    <style type="text/css">      <!--      table{      border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt;      mso-yfti-tbllook:480;mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-border-insideh:      .5pt solid windowtext;mso-border-insidev:.5pt solid windowtext;border-left:solid windowtext 1.0pt;border-top:solid windowtext 1.0pt;      }      td{      border-top:none;border-left:      none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;      mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;      mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt;      }      -->      </style>  

打字系统项目中的一个导出为EXCEL文件的实例代码如下:

Asp代码

    <!--#include file="hbwlConfig.asp" -->      <%Response.ContentType ="application/vnd.ms-excel"        Response.AddHeader "Content-Disposition", "attachment; filename=chengji.xls"%>      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">      <html xmlns="http://www.w3.org/1999/xhtml">      <head>      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />      <title>打字成绩</title>      <style type="text/css">      .tableWg {border:1px solid #9bbde6;}      .tableWg tr{text-align:center;}      .tableWg td{ border-bottom:1px dotted #9bbde6; border-right:1px dotted #9bbde6;}      </style>      </head>      <body>      <%sql=session("chengjisql")      response.Write hbwl.dbSelect(sql,0,1,"",0,"",0,"tableWg")%>      </body>      </html>      <%set hbwl=nothing%>  
0 0
原创粉丝点击