js导出excel表格
来源:互联网 发布:中子星 知乎 编辑:程序博客网 时间:2024/05/21 06:17
function exportFile() { var data = { 'key': [ {'value': "标题1"}, {'value': "标题2"} ], 'value': [ [ {'value': "内容11"}, {'value': "内容21"} ], [ {'value': "内容12"}, {'value': "内容22"} ], [ {'value': "内容13"}, {'value': "内容23"} ] ] }; if (data == '') return; var url = jsonToExcel(data.value, data.key); window.open(url); } function jsonToExcel(value, key) { var value = typeof value != 'object' ? JSON.parse(value) : value; var excel = '<table>'; //设置表头 var row = "<tr>"; for (var i = 0, l = key.length; i < l; i++) { row += "<td>" + key[i].value + '</td>'; } //换行 excel += row + "</tr>"; //设置数据 for (var i = 0; i < value.length; i++) { var row = "<tr>"; for (var j = 0; j < value[i].length; j++) { var tableValue = value[i][j].value; row += '<td>' + tableValue + '</td>'; } excel += row + "</tr>"; } excel += "</table>"; var excelFile = "<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'>"; excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">'; excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel'; excelFile += '; charset=UTF-8">'; excelFile += "<head>"; excelFile += "<!--[if gte mso 9]>"; excelFile += "<xml>"; excelFile += "<x:ExcelWorkbook>"; excelFile += "<x:ExcelWorksheets>"; excelFile += "<x:ExcelWorksheet>"; excelFile += "<x:Name>"; excelFile += "{worksheet}"; excelFile += "</x:Name>"; excelFile += "<x:WorksheetOptions>"; excelFile += "<x:DisplayGridlines/>"; excelFile += "</x:WorksheetOptions>"; excelFile += "</x:ExcelWorksheet>"; excelFile += "</x:ExcelWorksheets>"; excelFile += "</x:ExcelWorkbook>"; excelFile += "</xml>"; excelFile += "<![endif]-->"; excelFile += "</head>"; excelFile += "<body>"; excelFile += excel; excelFile += "</body>"; excelFile += "</html>"; var url = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile); return url; }
阅读全文
0 0
- JS导出excel表格
- JS导出excel表格
- js导出excel表格
- js导出excel表格
- js前端导出excel表格
- 用js导出Excel表格
- node.js导出excel表格----excel-export
- js实现html表格导出到excel
- js导出表格数据到word、excel
- js直接导出表格到excel
- js 将table表格导出excel
- js将表格内容导出到excel
- js实现html表格导出到excel
- JS调用页面表格导出excel
- js实现html表格导出到excel
- 前端JS实现导出EXCEL表格
- js导出页面表格数据到Excel
- js实现导出excel(可以导出表格线)
- 谈谈程序员的离职和跳槽
- OpenXml生成Word
- project euler 16 Power digit sum
- 图片上传-并发性知识
- 谈谈Shiro的原理及在SSM和SpringBoot两种环境下的使用姿势(上篇)
- js导出excel表格
- Qt构建、运行、qmake的区别
- thrift/swift:ThriftMethodProcessor代码分析
- ssh免密码登陆
- C#_类和方法
- 打包 【SSL JudgeOnline 2294】
- centos6.5中搭建hadoop-2.6.0时使用rpm包安装mysql5.7.20 初始化出错解决方法
- 基础知识-域名与IP
- [UGUI][Unity插件]迷你地图小地图雷达系统及其使用方法