Posted 9 July 2019, 2:07 pm EST
I am using SpreadJS.
I am trying to automatically save a user altered spreadsheet and automatically repopulate the spreadsheet later. To fetch user changes I did the following:
window.onblur = function () { const spread = new GC.Spread.Sheets.Workbook(document.getElementById("spreadsheetId")); let jsonStr = JSON.stringify(spread.toJSON()); console.log(jsonStr); }
output: {“version”:“12.0.8”,“sheetCount”:3,“sheets”:{“Sheet1”:{“name”:“Sheet1”,“theme”:“Office”,“data”:{“defaultDataNode”:{“style”:{“themeFont”:“Body”}}},“rowHeaderData”:{“defaultDataNode”:{“style”:{“themeFont”:“Body”}}},“colHeaderData”:{“defaultDataNode”:{“style”:{“themeFont”:“Body”}}},“selections”:{“0”:{“row”:0,“rowCount”:1,“col”:0,“colCount”:1},“length”:1},“index”:0},“Sheet2”:{“name”:“Sheet2”,“theme”:“Office”,“data”:{},“rowHeaderData”:{},“colHeaderData”:{},“selections”:{“0”:{“row”:0,“rowCount”:1,“col”:0,“colCount”:1},“length”:1},“index”:1},“Sheet3”:{“name”:“Sheet3”,“theme”:“Office”,“data”:{},“rowHeaderData”:{},“colHeaderData”:{},“selections”:{“0”:{“row”:0,“rowCount”:1,“col”:0,“colCount”:1},“length”:1},“index”:2}}}
As you can see the dataTableis missing and so there is no data that can be repopulated.
When I save the file via File > Export Export SSJSON File. I can see the full output including the dataTable property which contains all user data
output: {“version”:“12.0.8”,“sheetCount”:2,“sheets”:{“Sheet1”:{“name”:“Sheet1”,“activeRow”:16,“activeCol”:9,“theme”:“Office”,“data”:{“dataTable”:{“0”:{“0”:{“style”:{“hAlign”:3,“vAlign”:0,“themeFont”:“Body”,“imeMode”:1}},“1”:{“value”:“Expectancy: “,“style”:{“hAlign”:3,“vAlign”:0,“themeFont”:“Body”,“imeMode”:1}},“2”:{“value”:0.48,“style”:{“hAlign”:3,“vAlign”:0,“themeFont”:“Body”,“imeMode”:1}},“3”:{“style”:{“hAlign”:3,“vAlign”:0,“themeFont”:“Body”,“imeMode”:1}},“4”:{“value”:“Total P&L:”,“style”:{“hAlign”:3,“vAlign”:0,“themeFont”:“Body”,“imeMode”:1}},“5”:{“value”:776,“style”:{“autoFormatter”:{“formatCached”:”$#,##0.00;Red”},“hAlign”:3,“vAlign”:0,“themeFont”:“Body”,"imeMode …
How to I automatically export the state of the spreadsheet using javascript without users having to explicitly export the spreadsheet?
Again the objective is to stringify the entire spreasheet and load it again later.
Thanks