chrome浏览器js 导出excel
2016-12-13 15:01
357 查看
<table id="table"> <tr> <th>ID</th> <th>姓名</th> <th>年龄</th> <th>职业</th> <th>地区</th> <th>邮箱</th> </tr> <tr> <td>1</td> <td>admin</td> <td>23</td> <td>程序员</td> <td>天津</td> <td>admin@kali.com</td> </tr> <tr> <td>2</td> <td>guest</td> <td>23</td> <td>测试员</td> <td>北京</td> <td>guest@kali.com</td> </tr> </table> <input id="Button1" type="button" value="导出EXCEL"onclick="tableToExcel('table','测试')" />
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 version="1.0" encoding="UTF-8" standalone="yes"?><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)) } })()
相关文章推荐
- [JS]WEB页面导出为EXCEL文档的方法--转
- MSN弹出式窗口popup的JS实现及GridView导出Excel 〔转载〕
- js导出表格到word及excel(ie only)
- js 导出Excel
- JS导出Excel/word
- 用js导出数据到Excel文档
- js导出excel
- 关于js操作word和excel,js导出word和excel的若干方法汇总[转]
- js将table导出到excel
- js随机抽人员比赛并导出为excel
- js将html中的内容导出word、或者excel文件的方法
- JS 导出导入到 Excel 转
- 利用js导出Excel
- js将html中的内容导出word、或者excel文件的方法
- [转]JS导出内容到Excel,Word文档
- [Jscript]Js导出Excel
- JS导出EXCEL
- js实现导出excel(可以导出表格线)
- Js导出到Excel
- js导出Excel