单击按钮从经典的ASP生成Excel工作表 [英] Generate excel sheet from classic asp on click of button

查看:245
本文介绍了单击按钮从经典的ASP生成Excel工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过单击按钮创建一个Excel工作表. 这些Excel工作表将包含在经典ASP页面上生成的报告.当用户单击按钮时,应创建一个与工作表具有相同报告的Excel工作表

I want to create an excel sheet from click of button. These excel sheet will contain report which is generated on classic asp page. When user clicks on button then an excel sheet should be created which will have the same report as page have

推荐答案

此标头工作正常:

 <%
  Response.AddHeader "Content-Disposition", "attachment;filename=NOMBRE_ARCHIVO.xls"  
  Response.ContentType = "application/vnd.ms-excel" 
 %>

对于小型表格,请在html/javascript中尝试以下示例:

For small tables, try this example in html/javascript:

<html>
    <body>
        <table id="tabla" border="1">
            <tr><th>Uno</th><td>1</td></tr>
            <tr><th>Dos</th><td>2</td></tr>         
        </table>
        <p>
            <input type="button" onclick="javascript:exportarExcel('tabla');" value="Vamos al excel!">
        </p>
    </body>

    <script type="text/javascript">
    function exportarExcel(tabla){
        var t = document.getElementById(tabla);
        t.border = 1;
        var html = t.outerHTML;
        html = encodeURIComponent(html);
        // problemas con el encoding!
        // se puede usar base64_encode() en lugar de encodeURIComponent(html))
        // ojo con encodeURIComponet() que está deprecada. lo mejor sería usar base64

        window.open('data:application/vnd.ms-excel,' + html);
    }
    </script>

</html>

这篇关于单击按钮从经典的ASP生成Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆