项目作者: zzyhappyzzy

项目描述 :
convert html table to excel file
高级语言: HTML
项目地址: git://github.com/zzyhappyzzy/table2excel.git
创建时间: 2018-02-06T10:02:34Z
项目社区:https://github.com/zzyhappyzzy/table2excel

开源协议:MIT License

下载


table转excel文件

将web包含的table转为excel文件

参考

https://github.com/clarketm/TableExport

说明

前段时间,朋友在收集一些信息,让我帮忙将网页的table导成excel文件。由于我对网页开发并不熟悉,上网搜索了一番,最终定下初步方案,在此做个记录

使用

直接修改hongqi.html文件即可

注意

  1. html文件的header最好不做修改
    1. <head>
    2. <script src="Blob.min.js"></script>
    3. <script src="xlsx.core.min.js"></script>
    4. <script src="FileSaver.min.js"></script>
    5. <script src="tableexport.min.js"></script>
    6. </head>
  2. body部分:table转excel的script必须在table定义之后
    1. <body>
    2. <table>
    3. </table>
    4. <script>
    5. TableExport(document.getElementsByTagName('table'));
    6. // TableExport(document.getElementsByTagName("table"), {
    7. // headers: true, // (Boolean), display table headers (th or td elements) in the <thead>, (default: true)
    8. // footers: true, // (Boolean), display table footers (th or td elements) in the <tfoot>, (default: false)
    9. // formats: ['xlsx', 'csv', 'txt'], // (String[]), filetype(s) for the export, (default: ['xlsx', 'csv', 'txt'])
    10. // filename: 'id', // (id, String), filename for the downloaded file, (default: 'id')
    11. // bootstrap: false, // (Boolean), style buttons using bootstrap, (default: true)
    12. // exportButtons: true, // (Boolean), automatically generate the built-in export buttons for each of the specified formats (default: true)
    13. // position: 'bottom', // (top, bottom), position of the caption element relative to table, (default: 'bottom')
    14. // ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file(s) (default: null)
    15. // ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file(s) (default: null)
    16. // trimWhitespace: true // (Boolean), remove all leading/trailing newlines, spaces, and tabs from cell text in the exported file(s) (default: false)
    17. // });
    18. </script>
    19. </body>
  3. 如果一切正常,会在table的上面出现一排导出按钮,点击即可下载
    Demo