XLSXUtils-4aee7c67.js 1.6 KB

1
  1. import{p as u,q as b,t as d}from"./vendor-ef68d560.js";const F=e=>{const i=((m=[],a={})=>m.map(c=>{const n={};return Object.keys(a).map(l=>{n[a[l]]=c[l]}),n}))(e.list,e.headers),r=u.json_to_sheet(i),s=u.book_new();u.book_append_sheet(s,r,`${e.sheetName}`),s.Sheets[e.sheetName]["!cols"]=e.cols||[],b(s,`${e.fileName}.xlsx`)},N=(e,t)=>new Promise((i,r)=>{if(!e||!e.target||!e.target.files||!e.target.files.length)return r("\u6587\u4EF6\u4E0D\u80FD\u4E3A\u7A7A");const s=e.target.files[0],m=s.name.match(/\.[^.]+$/)[0];if(![".xls",".xlsx"].includes(m))return r("\u6587\u4EF6\u7C7B\u578B\u9519\u8BEF\uFF0C\u53EA\u80FD\u9009\u62E9 .xls | .xlsx");const a={name:s.name,size:s.size,type:m,sheets:[],headers:[],data:[]},c=new FileReader;c.readAsArrayBuffer(s),c.onload=n=>{const l=n.target.result,p=d(l,{type:"binary",cellDates:!0});p.SheetNames.map(async(_,o)=>{let h=[],y=[],f=[];a.sheets.push({label:_,index:o,value:o});const w={};if(t&&t.length&&t[o]&&t[o].headers?(w.header=t[o].headers,h=u.sheet_to_json(p.Sheets[_],w),h.shift(),y=t[o].headers):(h=u.sheet_to_json(p.Sheets[_]),h.length&&(y=Object.keys(h[0]))),t&&t.length&&t[o]&&(t[o].format||t[o].trim)){const k=await j(h,t[o])}else f=h;a.headers.push(y),a.data.push(f),o===p.SheetNames.length-1&&i(a)})}}),j=(e=[],t)=>new Promise(i=>{const r=[];e.map(async(s,m)=>{const a=await S(s,t);r.push(a),m===e.length-1&&i(r)})}),S=(e,t)=>new Promise(i=>{const r=t.format||{},s=Object.keys(e),m={};s.map((a,c)=>{const n=a;let l=e[a];r[n]&&r[n].replace&&(l=r[n].replace[l]),t.trim&&t.trim===!0&&typeof l=="string"&&(l=l.trim()),m[n]=l,c===s.length-1&&i(m)})});export{F as E,N as I};