Posted 21 August 2024, 1:07 pm EST - Updated 21 August 2024, 1:10 pm EST
Hi,
I am trying to convert an excel buffer data to spread js buffer in NodeJs environment hosted on AWS lambda. I have the Spread Js license correctly set and I have all the global variables set along with canvas. I’m encountering ‘Incorrect file format’ when trying to import the blob to workbook. Here is the code snippet:
async function convertXlsxBufferToSjs(buffer: ArrayBuffer) {
// create a new workbook
const workbook = new GC.Spread.Sheets.Workbook();
// import array buffer data to a Blob
const blob = new Blob([buffer], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
});
console.log("entering workbook import");
return new Promise<Blob>((resolve, reject) => {
workbook.import(
//@ts-expect-error Blob should also work when importing using SpreadJs
blob,
() => {
workbook.save(
async (blob: Blob) => {
resolve(blob);
},
(e: unknown) => {
console.log("Error saving spreadsheet");
console.error(e);
reject(e);
},
{
includeEmptyRegionCells: false,
includeCalcModelCache: true,
}
);
},
(e: unknown) => {
console.log("Error loading blob, entered failure callback", e);
reject(e);
},
{
fileType: GC.Spread.Sheets.FileType.excel,
doNotRecalculateAfterLoad: true,
calcOnDemand: true,
}
);
});
}
Here the workbook.import() calls the failure callback with “Error loading blob, entered failure callback { errorCode: 1, errorMessage: ‘Incorrect file format.’ }”
can you please help me resolve this issue, thanks.
Maneesha