Posted 6 March 2019, 2:18 am EST
Hello,
I am trying to build a nodeJS application that will allow us to convert excel to spreadJS json and save it in our database and then at some point convert them back from spredJS Json to excel.
I am using excelIO api I am able to save from excel to json but when I take the same json and trying to convert from json to excel it gives
{ errorCode: 1, errorMessage: 'Incorrect file format.' }
Here is the sample code I am using to test the API before I write real production code
var mockBrowser = require('mock-browser').mocks.MockBrowser;
var fileReader = require('FileReader');
var fs = require('fs')
global.FileReader = fileReader;
global.window = mockBrowser.createWindow()
global.document = window.document
global.navigator = window.navigator
global.HTMLCollection = window.HTMLCollection
global.getComputedStyle = window.getComputedStyle
var GC = require('@grapecity/spread-sheets')
var GCExcel = require('@grapecity/spread-excelio');
var excelIo = new GCExcel.IO();
try {
var file = fs.readFileSync('/home/kpatel/Desktop/test.xlsx');
excelIo.open(file.buffer, (data) => {
//yay excel converted to json and I can save it in database
console.log(JSON.stringify(data));
//taking same json and trying to convert it back to excel its giving error here
excelIo.save(data, function (blob) {
console.log(blob);
}, function (e) {
console.error(e);
});
});
} catch (e) {
console.error("** Error manipulating spreadsheet **");
console.error(e);
}