Posted 28 January 2024, 6:32 pm EST
Hi,
Kindly refer to the following code snippet and the attached sample for importing the “.sjs” file in the node environment:
var wb = new GC.Spread.Sheets.Workbook();
const data = fs.readFileSync('./export.sjs');
const blob = new Blob([data.buffer], { type: "application/zip" });
blob.name = "export.sjs";
blob.stream = fs.createReadStream('./export.sjs');
wb.open(blob, function () {
let sheet = wb.getActiveSheet();
console.log('-------load sjs file-------');
console.log(sheet.name());
console.log(sheet.getValue(3, 4));
}, function (e) {
console.log(e); // error callback
}, {
includeUnusedStyles: false
});
var wb1 = new GC.Spread.Sheets.Workbook();
const data1 = fs.readFileSync('./blank.xlsx');
const blob1 = new Blob([data1.buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
blob1.name = "blank.xlsx";
blob1.stream = fs.createReadStream('blank.xlsx');
wb1.import(blob1, function () {
console.log('-------load excel file---------');
let sheet = wb1.getActiveSheet();
console.log(sheet.name());
console.log(sheet.getArray(0, 0, 3, 1));
}, function (msg) {
console.log(msg); // error callback
}, {
fileType: GC.Spread.Sheets.FileType.excel,
});
In the attached sample, kindly set the Valid License Key for the application to work correctly (line no. 20 on index.js) file. The sample uses the latest version of SpreadJS( v17.0.2) and therefore, set the valid License Key for V17. If you are using the V16, set the valid License Key for V16.
If you are still face the issue, kindly do share the sample with us. You could also modify the attached sample and share it with us with the issue you are facing.
Regards,
Ankit
sjs_node.zip