Download the latest SpreadJS trial

preface

The SpreadJS table control has a powerful ability to serialize and deserialize tables. Skilled use of this function to speed up the development progress, reduce the amount of code, reduce the complexity of business logic, deal with some special logic requirements and other effects.

Function introduction:

Serialization:

Serialization allows you to serialize the current entire spread into JSON format for storage. This can be done with the spain.tojson (serializationOption) method, which also provides options to control the serialization result:

Var serializationOption = {ignoreFormula: true, // If set to true, the formula is ignored and the formula is not serialized, only the result of the formula calculation is serialized to JSON. IgnoreStyle: true, / / if set to true then ignore styles, all of the style attribute will not be serialized in JSON rowHeadersAsFrozenColumns: True, / / convert outfits to freeze columns serialization columnHeadersAsFrozenRows: true, / / the column head into line freeze serialization includeBindingSource: True // Serialize the data-bound data source to json as well}

Deserialization:

By deserializing, you can deserialize previously serialized JSON objects into pages for display. This can be done with the spread2.fromjson (json, jsonOptions) method, which also provides options to control the results of deserialization:

Var jsonOptions = {ignoreFormula: true, // If this parameter is set to true, the formula is ignored. The formula is ignored during deserialization and only the deserialization of the formula is displayed on the page. IgnoreStyle: true, / / if set to true then ignore style, not to show the style attribute deserialization frozenColumnsAsRowHeaders: True, / / would freeze columns into wardrobe frozenRowsAsColumnHeaders: true, / / would freeze row into column head doNotRecalculateAfterLoad: true, / / after deserialization formula not recalculate}

Common usage scenarios:

1. Use serialization and deserialization in designer:

SpreadJS offers a designer that lets you quickly create templates by dragging, clicking and configuring them, saving you a lot of code editing. After you have designed the template in the designer, you can export the template to ssJSON files (which are generated as JSON files after serializing toJSON) through the designer’s export function.

When displaying the page, we can read the file in JS (such as jquery \$.getjson (), through js file reading, etc.) and deserialize the obtained JSON object into the page display through spread-fromjson. This completes a quick build of the template.

2. Differentiated treatment

Differential processing is often required in the user’s service logic. For example, the formula set in the template does not want to be exported when it is exported. This can be ignored by setting it in toJSON.

3. Export of multiple column headers

SpreadJS has some extensions, such as multiple column headers, that Excel does not support. This feature is often used in business logic, so if you need to export Excel at the same time, it can be a problem. To solve this problem, Before the export toJSON can set columnHeadersAsFrozenRows properties, later will generate json to ExcelIO when exported, such export Excel will SpreadJS multi-column head by freezing line for display. For example, the following table:

Set up more wardrobe and column head, if you want to export Excel contained in the wardrobe and column header information, can be set at the time of toJSON rowHeadersAsFrozenColumns and columnHeadersAsFrozenRows these two properties, After exporting, you can display the row header and column header information in Excel, like this:


SpreadJS | Download the trial

Pure front-end form control SpreadJS, is on the market layout and functions are highly similar to Excel a form control, full Chinese operation interface, suitable for. NET, Java, mobile terminal and other platforms like Excel data development, huawei, ZTO, Civil Aviation Flight Academy and other domestic well-known enterprise customers favor.