@sheetxl/io
Version:
IO - Import/Export Libraries for SheetXL.
7 lines (6 loc) • 1.91 kB
JavaScript
;/**
* @license @sheetxl/io - IO - Import/Export Libraries for SheetXL. - v0.7.27
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("@sheetxl/sdk");exports.readBufferCSV=async(i,u)=>{const{papaParseConfig:l,setValuesOptions:g,createWorkbookOptions:f}=u??{},n=u?.progress,h=n?.onProgress,m=await Promise.resolve().then(()=>require("./B4NauYFY7ESTtl4B.cjs")).then(r=>r.papaparse_min),o=new TextDecoder().decode(i);let p=-1;const d=new S.Workbook(f),t=d.getSelectedSheet().getEntireRange().startIncrementalUpdates({orientation:S.IRange.Orientation.Row});let e=0;const w={...l,transform:(r,s)=>{l?.transform&&(r=l.transform(r,s));const a=s;a===0&&p++;let c=r??"";return t.pushAt(p,a,c),e++,e%1e5==0&&h?.(e),r}};return m.parse(o,w).data,t.apply({textParser:!0,...g}),d},exports.writeBufferCSV=async(i,u)=>{const{trimLeadingBlankRow:l=!0,trimLeadingBlankColumn:g=!0,ignoreHidden:f=!1,sheetKey:n=null,papaParseConfig:h={}}=u||{},m=await Promise.resolve().then(()=>require("./B4NauYFY7ESTtl4B.cjs")).then(s=>s.papaparse_min);if(!i)throw new Error("workbook must be specified");let o=null;if(n===null?o=i.getSelectedSheet():typeof n=="number"?o=i.getSheets().getItems()[n]:typeof n=="string"&&(o=i.getSheets().getByName(n)),!o)throw new Error("invalid sheetKey specified");let p=null;const d=[];let t=null,e=o.getUsedRange({ignoreHidden:f});if(!e)throw new Error("Nothing to export");if(!l||!g){const s=l?e.getRowStart():0,a=g?e.getColumnStart():0;e=e.getOffsetTo(s,a)}e.forEach((s,a)=>{const c=a.getCoords(),y=a.getCell();p!==c.rowIndex&&(t&&d.push(t),t=[],p=c.rowIndex);const b=y.toTextUnformatted()??"";t.push(b)},{includeEmpty:!0,address:null}),t&&d.push(t);const w={...h},r=m.unparse(d,w);return new TextEncoder().encode(r).buffer};