当前位置: 首页 > ai >正文

jquery.table2excel方法导出

jquery提供了一个table2excel方法可以用来导出页面到xls等

 $("#grid_595607").table2excel({exclude: ".noExport", // 排除类名为 noExport 的元素filename: "导出数据.xls",exclude_img: true,    // 不导出图片exclude_links: true,  // 不导出链接exclude_inputs: true  // 不导出输入框内容});

grid_595607为列表的id,

导出时需要引入jquery.table2excel.min.js

以下是jquery.table2excel.min.js内容也可以自行下载

/**  jQuery table2excel - v1.1.1*  jQuery plugin to export an .xls file in browser from an HTML table*  https://github.com/rainabba/jquery-table2excel**  Made by rainabba*  Under MIT License*/
!function(a,b,c,d){function e(b,c){this.element=b,this.settings=a.extend({},k,c),this._defaults=k,this._name=j,this.init()}function f(a){return a.filename?a.filename:"table2excel"}function g(a){var b=/(\s+alt\s*=\s*"([^"]*)"|\s+alt\s*=\s*'([^']*)')/i;return a.replace(/<img[^>]*>/gi,function(a){var c=b.exec(a);return null!==c&&c.length>=2?c[2]:""})}function h(a){return a.replace(/<a[^>]*>|<\/a>/gi,"")}function i(a){var b=/(\s+value\s*=\s*"([^"]*)"|\s+value\s*=\s*'([^']*)')/i;return a.replace(/<input[^>]*>|<\/input>/gi,function(a){var c=b.exec(a);return null!==c&&c.length>=2?c[2]:""})}var j="table2excel",k={exclude:".noExl",name:"Table2Excel",filename:"table2excel",fileext:".xls",exclude_img:!0,exclude_links:!0,exclude_inputs:!0};e.prototype={init:function(){var b=this;b.template={head:'<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"><meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8"><head>\x3c!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets>',sheet:{head:"<x:ExcelWorksheet><x:Name>",tail:"</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>"},mid:"</x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--\x3e</head><body>",table:{head:"<table>",tail:"</table>"},foot:"</body></html>"},b.tableRows=[],a(b.element).each(function(c,d){var e="";a(d).find("tr").not(b.settings.exclude).each(function(c,d){e+="<tr>",a(d).find("td,th").not(b.settings.exclude).each(function(c,d){var f={rows:a(this).attr("rowspan"),cols:a(this).attr("colspan"),flag:a(d).find(b.settings.exclude)};f.flag.length>0?e+="<td> </td>":f.rows&f.cols?e+="<td>"+a(d).html()+"</td>":(e+="<td",f.rows>0&&(e+=" rowspan='"+f.rows+"' "),f.cols>0&&(e+=" colspan='"+f.cols+"' "),e+="/>"+a(d).html()+"</td>")}),e+="</tr>",console.log(e)}),b.settings.exclude_img&&(e=g(e)),b.settings.exclude_links&&(e=h(e)),b.settings.exclude_inputs&&(e=i(e)),b.tableRows.push(e)}),b.tableToExcel(b.tableRows,b.settings.name,b.settings.sheetName)},tableToExcel:function(d,e,g){var h,i,j,k=this,l="";if(k.format=function(a,b){return a.replace(/{(\w+)}/g,function(a,c){return b[c]})},g=void 0===g?"Sheet":g,k.ctx={worksheet:e||"Worksheet",table:d,sheetName:g},l=k.template.head,a.isArray(d))for(h in d)l+=k.template.sheet.head+g+h+k.template.sheet.tail;if(l+=k.template.mid,a.isArray(d))for(h in d)l+=k.template.table.head+"{table"+h+"}"+k.template.table.tail;l+=k.template.foot;for(h in d)k.ctx["table"+h]=d[h];if(delete k.ctx.table,!c.documentMode){var m=new Blob([k.format(l,k.ctx)],{type:"application/vnd.ms-excel"});b.URL=b.URL||b.webkitURL,i=b.URL.createObjectURL(m),j=c.createElement("a"),j.download=f(k.settings),j.href=i,c.body.appendChild(j),j.click(),c.body.removeChild(j)}else if("undefined"!=typeof Blob){l=k.format(l,k.ctx),l=[l];var n=new Blob(l,{type:"text/html"});b.navigator.msSaveBlob(n,f(k.settings))}else txtArea1.document.open("text/html","replace"),txtArea1.document.write(k.format(l,k.ctx)),txtArea1.document.close(),txtArea1.focus(),sa=txtArea1.document.execCommand("SaveAs",!0,f(k.settings));return!0}},a.fn[j]=function(b){var c=this;return c.each(function(){a.data(c,"plugin_"+j)||a.data(c,"plugin_"+j,new e(this,b))}),c}}(jQuery,window,document);

http://www.xdnf.cn/news/7966.html

相关文章:

  • 鸿蒙仓颉开发语言实战教程:实现商城应用首页
  • 尼科彻斯定理
  • Vue 3.0中自定义指令
  • 01-jenkins学习之旅-window-下载-安装
  • 【云原生安全】零信任与机密计算
  • Qt C++实现马的遍历问题
  • 【JavaEE】(1) 计算机如何工作
  • 阿里巴巴 MCP 分布式落地实践:快速转换 HSF 到 MCP server
  • 记录:uniapp 上线部署到微信小程序vendorjs包过大的问题
  • 外网如何连接内网中的mysql数据库服务器?简单网络工具方案
  • Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment
  • 【C++】位图+布隆过滤器
  • JAVA EE(进阶)_CSS
  • 如何排查服务器 CPU 温度过高的问题并解决?
  • C++ 前缀和数组
  • C++STL(二)类模板
  • YCKC【二分查找专题】题解
  • 《对话记忆的进化史:智能体大模型如何实现跨轮次的深度交互》
  • 国酒华夏实业酒水供应链:全品类覆盖打造一站式购销平台
  • 第四十三节:人脸检测与识别-人脸识别基础 (Eigenfaces, Fisherfaces, LBPH)
  • Selenium自动化测试终极指南:从原理到实战
  • 【Python生成器全解析】从基础到高阶应用实战
  • C语言—Linux环境下CMake设置库(动态/静态)
  • 借助IEDA ,Git版本管理工具快速入门
  • 多线程(七)
  • 开疆智能Profinet转RS485网关连接工业型土壤水分温度传感器 配置案例
  • 如何在 Windows 10 或 11 上安装 Adminer?
  • 非欧空间计算加速:图神经网络与微分几何计算的GPU优化(流形数据的内存布局优化策略)
  • MEMO数据DID与ZK技术:赋能RWA代币化与可信流通的新基石
  • BI 大屏是什么意思?具体应用在哪些方面?