Posted 8 May 2023, 3:34 pm EST
- Updated 8 May 2023, 3:39 pm EST
Hello,
Please refer to the answers below for your questions.
We are sorry for the inconvenience caused. SpreadJS (including ExcelIO.open()) does not support passing ReadableStream for importing xlsx file.
The IO module which implements workbook.import(), workbook.export(), workbook.save(), workbook.open() APIs is different from ExcelIO module. The IO module was released in SpreadJS V16. There is a difference in their implementation.
The recommended way of importing xlsx files is to use new IO module. It has improved performance as the excel file can be imported directly without converting it to json and then loading on spread like ExcelIO module does. Also, IO module support SJS file format which is SpreadJS specific file format. SJS file format is basically a zipped folder. It reduces the overall size of files and has improved loading performance. You can also import xlsx, sjs file in lazy load and incremental load to reduce loading time.
Please refer to https://www.grapecity.com/spreadjs/docs/features/spreadjs-file-format#site_main_content-doc-content_title for more information on SJS format respectively.
Please note that SpreadJS ExcelIO and IO module does not support importing xlsx file using readable streams. However, you can load xlsx file from the blob files.
Please refer to the code snippet which demonstrates how you can import xlsx file with ExcelIO and IO module respectively.
// imports xlsx file using ExcelIO module
async function loadUsingExcelIO(spread, url) {
const excelIo = new GC.Spread.Excel.IO();
const blob = await fetch(url).then(res => res.blob());
return new Promise((resolve, reject) => {
excelIo.open(
blob,
function (json) {
spread.fromJSON(json);
resolve('file loaded successfully');
},
function (e) {
console.error(e);
reject(e);
}
);
});
}
// imports xlsx file using IO module
async function loadUsingIO(spread, url) {
const excelIo = new GC.Spread.Excel.IO();
const blob = await fetch(url).then(res => res.blob());
return new Promise((resolve, reject) => {
spread.import(blob, () => {
resolve('file loaded successfully');
}, () => {
reject(e);
});
});
}
Please let us know if you face any issues or if you have any doubts. We will help you accordingly.
Regards,
Avinash