zoukankan      html  css  js  c++  java
  • JS导出gridview到excel

    <html>
    <head>
        <script type="text/javascript">
            var tableToExcel = (function () {
                var uri = 'data:application/vnd.ms-excel;base64,'
        , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
        , base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
        , format = function (s, c) { return s.replace(/{(w+)}/g, function (m, p) { return c[p]; }) }
                return function (table, name) {
                    if (!table.nodeType) table = document.getElementById(table)
                    var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
                    window.location.href = uri + base64(format(template, ctx))
                }
            })()
        </script>
    </head>
    <body>
        <h1>
            tableToExcel Demo</h1>
        <p>
            Exporting the W3C Example Table</p>
        <input type="button" onclick="tableToExcel('GridViewBoiler', 'W3C Example Table')"
            value="Export to Excel">
        <table cellspacing="0" cellpadding="4" rules="all" border="1" id="Table1" style="color: #333333;
             100%; border-collapse: collapse;">
            <tbody>
                <tr style="color: White; background-color: #507CD1; font-weight: bold;">
                    <th scope="col">
                        序号
                    </th>
                    <th scope="col">
                        参数描述
                    </th>
                    <th scope="col">
                        --望亭发电有限公司--#11机组--锅炉本体试验--2015-02-09 14:40:53--
                    </th>
                </tr>
                <tr style="background-color: #EFF3FB;">
                    <td align="center">
                        1
                    </td>
                    <td align="left">
                        入炉煤收到基低位发热量(KJ/Kg)
                    </td>
                    <td>
                        19600.0000
                    </td>
                </tr>
                <tr style="background-color: White;">
                    <td align="center">
                        2
                    </td>
                    <td align="left">
                        入炉煤收到基灰分(%)
                    </td>
                    <td>
                        23.6000
                    </td>
                </tr>
                <tr style="background-color: #EFF3FB;">
                    <td align="center">
                        3
                    </td>
                    <td align="left">
                        入炉煤收到基水分(%)
                    </td>
                    <td>
                        4.1800
                    </td>
                </tr>
                <tr style="background-color: White;">
                    <td align="center">
                        4
                    </td>
                    <td align="left">
                        入炉煤收到基碳含量(%)
                    </td>
                    <td>
                        57.4900
                    </td>
                </tr>
                <tr style="background-color: #EFF3FB;">
                    <td align="center">
                        5
                    </td>
                    <td align="left">
                        入炉煤收到基氢含量(%)
                    </td>
                    <td>
                        3.6500
                    </td>
                </tr>
                <tr style="background-color: White;">
                    <td align="center">
                        6
                    </td>
                    <td align="left">
                        入炉煤收到基氧含量(%)
                    </td>
                    <td>
                        9.9500
                    </td>
                </tr>
                <tr style="background-color: White;">
                    <td align="center">
                        20
                    </td>
                    <td align="left">
                        换算至设计送风温度时的排烟温度(%)
                    </td>
                    <td>
                        122.0239
                    </td>
                </tr>
                <tr style="background-color: #EFF3FB;">
                    <td align="center">
                        21
                    </td>
                    <td align="left">
                        修正后锅炉热效率(%)
                    </td>
                    <td>
                        91.2669
                    </td>
                </tr>
            </tbody>
        </table>
    </body>
    </html>
  • 相关阅读:
    25个Apache性能优化技巧推荐 新风宇宙
    九个PHP很有用的功能 新风宇宙
    ubuntu nginx的安装 新风宇宙
    .net 下对winapi的调用
    jquery选中单选框、复选框、下拉框
    中国标准书号校验码的计算方式(附C#代码)
    NET中创建一个线程有几种方法
    ASP.NET中Cookie编程的基础知识
    js日期时间函数(经典+完善+实用)
    SQL语句大全
  • 原文地址:https://www.cnblogs.com/ilookbo/p/5057245.html
Copyright © 2011-2022 走看看