在asp程序中打印excel表格的新方法

字號:


    在asp程序中打印excel報表的新方法
    目前,b/s模式(瀏覽器/服務(wù)器模式)成為企業(yè)網(wǎng)上首選的計算模式。由于b/s模式的特殊性,在c/s下相對較易實現(xiàn)的excel報表打印功能在b/s下卻成為一個難點。本人通過研究寫了一個基于asp程序的打印excel報表的程序。本程序的特點是無須任何組件。
    print.asp
    ------------------------------------------------
    <html><title>打印excel報表</title>
    <%
    '控制腳本語言
    response.write<script language=&vbscript&>
    %>
    //*****************本程序由火星工作室提供()******************
    //*******************版權(quán)所有 隨意拷貝********************************
    function ccprint()
    set xlapp = createobject(excel.application)
    //打開工作表!
    set xlbook = xlapp.workbooks.open(c:book1.xlt)
    set xlsheet1 = xlbook.activesheet
    <% db=zhk.mdb
    set conn = server.createobject(adodb.connection)
    connstr=provider=microsoft.jet.oledb.4.0;data source= & server.mappath(&db&)
    conn.open connstr
    set rsd=server.createobject(adodb.recordset)
    str=select * from cjb00
    rsd.open str,conn
    ii=1
    do while not rsd.eof and ii<11
    %>
    <%response.writexlsheet1.cells(&ii+4&,2).value=%><%=rsd(姓名)%>
    <%response.writexlsheet1.cells(&ii+4&,3).value=%><%=rsd(學(xué)號)%>
    <%
    rsd.movenext
    ii=ii+1
    loop
    rsd.close
    set rsd=nothing
    %>
    xlsheet1.application.visible = true
    end function
    //*****************本程序由火星工作室提供******************
    <%
    response.write</script>
    %>
    <html><title>打印excel報表</title>
    <body>
    <center>
    <h2><font color=red>學(xué)生表(demo)</font></h2>
    <p>&nbsp;</p>
    <form name=fmp method=post action=>
    <%
    db=zhk.mdb
    set conn = server.createobject(adodb.connection)
    connstr=provider=microsoft.jet.oledb.4.0;data source= & server.mappath(&db&)
    conn.open connstr
    set rsd=server.createobject(adodb.recordset)
    str=select * from cjb00
    rsd.open str,conn
    %>
    <table width=396 height=58 border=1 bordercolor=#00ff00 bgcolor=lightyellow>
    <tr bgcolor=deepskyblue>
    <th><b>姓名</b></th>
    <th><b>學(xué)號</b></th>
    </tr>
    <%
    do while not rsd.eof
    %>
    <tr>
    <td> <%=rsd(姓名)%>
    </td>
    <td> <%=rsd(學(xué)號)%>
    </td>
    </tr>
    <%
    rsd.movenext
    loop
    %>
    <% rsd.close
    set rsd=nothing
    conn.close
    set cnn=nothing %>
    </table>
    <p>
    <input name=submit2 type=button onclick=ccprint() ondblclick=ccprint() value=打印>
    <br>
    </p>
    </form>
    </center>
    </body>
    </html>