UNPKG

eltable-as-xlsx

Version:
3 lines (2 loc) 2.09 kB
(function(a,b){if("function"==typeof define&&define.amd)define(["exports","file-saver","xlsx"],b);else if("undefined"!=typeof exports)b(exports,require("file-saver"),require("xlsx"));else{var c={exports:{}};b(c.exports,a.fileSaver,a.xlsx),a.index=c.exports}})("undefined"==typeof globalThis?"undefined"==typeof self?this:self:globalThis,function(a,b,c){"use strict";function d(a){if("function"!=typeof WeakMap)return null;var b=new WeakMap,c=new WeakMap;return(d=function(a){return a?c:b})(a)}function e(a,b){if(!b&&a&&a.__esModule)return a;if(null===a||"object"!=typeof a&&"function"!=typeof a)return{default:a};var c=d(b);if(c&&c.has(a))return c.get(a);var e={},f=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var g in a)if("default"!=g&&Object.prototype.hasOwnProperty.call(a,g)){var h=f?Object.getOwnPropertyDescriptor(a,g):null;h&&(h.get||h.set)?Object.defineProperty(e,g,h):e[g]=a[g]}return e.default=a,c&&c.set(a,e),e}function f(a){let b=[];for(let c=0;c<a.length;c++){const d=a[c],e=d.cells;for(let a=0;a<e.length;a++){const c=e[a],d=c.innerText,f=c.clientWidth+20;(!b[a]||b[a]<f)&&(b[a]=f)}}return b}Object.defineProperty(a,"__esModule",{value:!0}),a.exportExcel=void 0,b=function(a){return a&&a.__esModule?a:{default:a}}(b),c=e(c);const g=({id:a,fileName:d,excludeColumns:e=[]})=>{const g=document.querySelectorAll(`#${a} table > thead > tr th`),h=document.querySelectorAll(`#${a} table > tbody > tr`);let j=[];for(let b=0;b<h.length;b++){const a=h[b];let c=[];const d=a.cells;for(let a=0;a<d.length;a++){const b=d[a],f=g[a].innerText,h=+g[a].getAttribute("colspan");if(!e.includes(f)||1<h){const a=b.innerText;c.push(a)}}j.push(c)}const k=[];for(let b=0;b<g.length;b++){const a=g[b].innerText;e.includes(a)||k.push(a)}j.unshift(k);const i=c.utils.aoa_to_sheet(j),l=f(h);i["!cols"]=l.map(a=>({width:a/6.4}));const m=c.utils.book_new();c.utils.book_append_sheet(m,i,"Sheet");const n=c.write(m,{bookType:"xlsx",type:"array"});b.default.saveAs(new Blob([n],{type:"application/octet-stream"}),`${d}.xlsx`)};a.exportExcel=g}); //# sourceMappingURL=eltable-as-xlsx.min.js.map