How can I get / save the cell formatting. I need to save it into database?
I any method to get and save the state of the spreadsheet (filters, cell formating, row formatting, sorting)?
basically, most of the cell metadata can be picked from getCellMeta(row, col)
method. So you would need to iterate the spreadsheet to get all cells.
When it comes to sorting and filtering here are two demos that logs all needed data,
filtering: http://jsfiddle.net/handsoncode/L92psp5s/
sorting: http://jsfiddle.net/handsoncode/vnh0zxpn/
Here’s an interesting observation for you:
I have to save cell properties, and my own code enumerates the explicit properties I want out of getCellMeta()
to save, which works. However, I thought for this question I’d post that you could do a JSON.stringify(getCellMeta())
to get a string representation to save.
If you do that, however, you get a JavaScript error Circular reference in value argument not supported
. On a hunch I guessed that might be because of cellMeta.instance
(which anyway is way big, and you would not want to save it). If you set that to undefined
, or delete cellMeta.instance
, sure enough JSON.stringify(cellMeta)
now works.
However, it appears that the object returned by getCellMeta()
is a reference to an actual object used for cell properties, not just a copy/constructed one. So you cannot afford to just undefine
/delete
it. That leaves two possibilities:
var cellMeta = hot.getCellMeta(row, col);
cellMeta = _.clone(cellMeta);
cellMeta.instance = undefined;
var str = JSON.stringify(cellMeta);
or
var cellMeta = hot.getCellMeta(row, col);
var instance = cellMeta.instance;
callMeta.instance = undefined;
var str = JSON.stringify(cellMeta);
cellMeta.instance = instance;
P.S.
In addition to what getCellMeta(row, col)
returns, there is a slew of further “meta” information you may want to save, including:
-
getColWidth(col)
/getRowHeight(row)
-
getColHeader(col)
/getRowHeader(row)
- Other stuff you may have set in top-level
options
.