UNPKG

mr-excel

Version:

A versatile JavaScript library for effortlessly generating .xlsx files from input objects. Seamlessly create Excel spreadsheets with data, formatting, formulas, and more.

2 lines (1 loc) 2.45 kB
define(["require","exports","./index-D3jbCDy2"],function(M,N,b){"use strict";function P(s){return/t="s".*?<v/.test(s)}function R(s){const a=/<t.*?>(.*?)<\/t>/,r=s.match(a);return r?r[1]:null}function B(s){const a=/<v.*?>(.*?)<\/v>/,r=s.match(a);return r?r[1]:null}function D(s){const a=/r="(.*?)"/,r=s.match(a);return r?r[1]:null}async function $(s,a=!1,r){let O,A=!1;typeof r=="function"?(O=r,A=!0):O=fetch;let x=[],y=new Map,C={},E=[],k={},V={},T=!1;function j(t,I){let g=0,f=[],i=I.match(/<c[\s\S\n]*?<\/c>/g);if(Array.isArray(i)&&i.forEach(n=>{let h=B(n);P(n)&&h&&(h=E[parseInt(h)]);const p=D(n);let c=b.getColRowBaseOnRefString(p,b.cols);typeof f[c.row]>"u"&&(f[c.row]=[]),f[c.row][c.col]=h,g=Math.max(c.col,g)}),t.indexOf("xl/worksheets/sheet")==0){let n=t.substring(14,t.lastIndexOf("."));y.has(n)&&(n=y.get(n)),k[n]=f,V[n]=g}}return await O(s).then(t=>{if(t==null||t==null)throw"response is null";return A?t:a?t.arrayBuffer():t.blob()}).then(async t=>{const g=(await new Promise((i,n)=>M(["./jszip.min-CGrYsaMq"],i,n)).then(i=>i.jszip_min)).default;let f=0;return await new Promise((i,n)=>{g.loadAsync(t).then(function(h){const p=Object.keys(h.files);f=p.length;let c=new Proxy({counter:0,isNameSet:!1},{set(e,o,u){if(o==="isNameSet")return e.isNameSet=u,!0;if(typeof u!="number")throw"value most be number";return e.counter=u,e.isNameSet&&e.counter===f&&i({data:k,sheetNameObject:C,sheetName:y.entries(),maxLengthOfColumn:V}),!0},get(e,o,u){return o==="isNameSet"?e.isNameSet:e.counter}});p.forEach(function(e){h.files[e].async("string").then(function(o){if(e.indexOf("sharedStrings")>=0){let u=o.match(/<si[\s\S\n]*?<\/si>/g);Array.isArray(u)&&u.forEach(S=>{let m=S.match(/<t[\s\S\n]*?<\/t>/g);if(Array.isArray(m)){let w=m.reduce((l,d)=>l+R(d),"");E.push(w)}}),T=!0,x.length>0&&(x.forEach(S=>{j(S.filename,S.fileData)}),x=[])}e.indexOf("sheet")>=0&&(T?j(e,o):x.push({filename:e,fileData:o})),e.indexOf("workbook")>=0&&(o.replace(/(.*[\n\s\S]*)(<sheets[\n\s\S]*?sheets>)(.*[\n\s\S]*)/,"$2").split("<sheet ").slice(1).forEach((m,w)=>{let l=w+1,d="Sheet "+l;m.indexOf("name=")>=0&&(d=m.replace(/(.*[\n\s\S]*?)name="([^"]*)"(.*[\n\s\S]*)/,"$2")),m.indexOf("sheetId=")>0&&(l=Number(m.replace(/(.*[\n\s\S]*?)sheetId="([^"]*)"(.*[\n\s\S]*)/,"$2")),isNaN(l)&&(l=w+1)),y.set("sheet"+l,d),C["sheet"+l]=d}),c.isNameSet=!0),c.counter++})})})})}).catch(t=>{throw t})}N.extractExcelData=$,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});