serialize()
Description
Serializes the spreadsheet data into a JSON object
Usage
serialize(): {
sheets: [
{
name: string,
id: string,
data: [
{
cell: string,
value?: string | number,
css?: string,
format?: string,
editor?: {
type: string, // type: "select"
options: string | array
},
locked?: boolean,
link?: {
text?: string,
href: string
}
},
// more cell objects
],
cols: [
{
width: number,
hidden: boolean
},
// more column objects
],
rows: [
{
height: number,
hidden: boolean
},
// more row objects
],
merged: [
{
from: { column: number, row: number },
to: { column: number, row: number }
},
// more objects
],
freeze: {
col: number,
row: number
}
},
// more sheet objects
],
styles: object,
formats: array
};
Returns
The method returns a serialized JSON object with the following attributes:
formats- an array of objects with number formatsstyles- an object with the applied CSS classes, where a key is the name of a class and a value is an object with its style propertiessheets- an array of sheet objects. Each object contains the following attributes:name- the sheet nameid- the sheet iddata- an array of cell objects. Each object contains thecellattribute with the cell id and the attributes that were set for the cell:value,css,format,editor,locked,linkcols- an array of objects with columns configurations. Each object contains thewidthandhiddenattributesrows- an array of objects with rows configurations. Each object contains theheightandhiddenattributesmerged- an array of objects where each object defines a range of merged cells via thefromandtoattributesfreeze- an object with the number of fixed columns and rows,{ col: 0, row: 0 }if nothing is frozen
Note that:
- the
mergedandfreezeattributes are always present in a sheet object, as well as thehiddenattribute in a column or row object, which isfalsewhen the column or row is visible - the
colsandrowsarrays cover the data range of a sheet and are extended further if a column width, a row height, or ahiddenstate was changed beyond that range. Thus custom sizes of empty columns and rows are kept as well - a cell gets into the
dataarray if it has a value, a CSS class, an editor, or thelockedstate. Thus locked empty cells are kept as well - the returned object can be passed to the parse() method as is
Example
const spreadsheet = new dhx.Spreadsheet("spreadsheet", {});
spreadsheet.parse(data);
const state = spreadsheet.serialize();
Related article: Data loading and export