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