Skip to content

Commit e11b9e3

Browse files
committed
1014442: added contents for open/save in json
1 parent afb9287 commit e11b9e3

15 files changed

Lines changed: 2355 additions & 0 deletions

File tree

Document-Processing/Excel/Spreadsheet/React/open-excel-files.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,27 @@ Please find the code to fetch the blob data and load it into the Spreadsheet com
160160
161161
{% previewsample "/document-processing/code-snippet/spreadsheet/react/open-from-blobdata-cs1" %}
162162
163+
### Open from JSON
164+
165+
The [openFromJson](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#openfromjson) method lets you load a complete workbook into the Spreadsheet using a JSON object. This JSON is usually created on the server after converting an Excel file, but it can also be generated manually. The method reads the JSON and restores all sheets, cells, styles, formulas, formatting, and other workbook details inside the component.
166+
167+
openFromJson is used because it provides a smooth and reliable way to load Excel data into the browser without needing the actual Excel file. Since the file is already processed into JSON on the server, the client only handles lightweight data. This reduces the workload on the browser and ensures that the document structure, formatting, and content appear exactly as intended. It also allows developers to modify or build workbook data directly in JSON form before loading it into the spreadsheet.
168+
169+
The main benefit for users is a faster and more stable loading experience. Because the heavy Excel‑processing work is completed on the server, the spreadsheet opens quickly in the browser and maintains the correct layout, values, and styles. The JSON format helps avoid common issues that might occur with large or complex Excel files, making the entire experience more dependable and easier for users.
170+
171+
The following code snippet demonstrates openFromJson method:
172+
173+
{% tabs %}
174+
{% highlight js tabtitle="app.jsx" %}
175+
{% include code-snippet/spreadsheet/react/open-from-json-cs1/app/app.jsx %}
176+
{% endhighlight %}
177+
{% highlight ts tabtitle="app.tsx" %}
178+
{% include code-snippet/spreadsheet/react/open-from-json-cs1/app/app.tsx %}
179+
{% endhighlight %}
180+
{% endtabs %}
181+
182+
{% previewsample "/document-processing/code-snippet/spreadsheet/react/open-from-json-cs1" %}
183+
163184
### Load server-side Excel files into Spreadsheet
164185
165186
By default, the Spreadsheet component provides an option to browse files from the local file system and open them within the component. If you want to load an Excel file located on a server, you need to configure the server endpoint to fetch the Excel file from the server location, process it using `Syncfusion.EJ2.Spreadsheet.AspNet.Core`, and send it back to the client side as `JSON data`. On the client side, you should use the [openFromJson](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#openfromjson) method to load that `JSON data` into the Spreadsheet component.

Document-Processing/Excel/Spreadsheet/React/rows-and-columns.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ You can change the size of rows and columns in the spreadsheet by using [setRows
155155

156156
You can change the height of single or multiple rows by using the [setRowsHeight](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/#setrowsheight) method.
157157

158+
There is a property `customHeight` on a row’s model that indicates the row height has been explicitly set by dragging the row header boundary with the mouse or by a programmatic resize. The Spreadsheet sets this property using the setRow method during a resize operation.
159+
160+
When customHeight is true, it means the height was manually defined rather than automatically determined from cell content or formatting.
161+
162+
Actions such as enabling Wrap Text, increasing font size, or changing the font family do not set `customHeight` property.
163+
158164
You can provide the following type of ranges to the method:
159165

160166
* Single row range: `['2:2']`
@@ -185,6 +191,12 @@ The following code example shows how to change the height for single/multiple ro
185191

186192
You can change the width of single or multiple columns by using the [setColumnsWidth](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/#setcolumnswidth) method.
187193

194+
There is a property `customWidth` on a column’s model that indicates the column width has been explicitly set by dragging the column header boundary with the mouse or by a programmatic resize. The Spreadsheet sets this property using the `setColumn` method during a resize operation.
195+
196+
When `customWidth` is true, it means the width was manually defined rather than automatically determined based on cell content or formatting.
197+
198+
Actions such as enabling Wrap Text, increasing font size, or changing the font family do not set `customHeight` property.
199+
188200
You can provide the following type of ranges to the method:
189201

190202
* Single column range: `['F:F']`

Document-Processing/Excel/Spreadsheet/React/save-excel-files.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,30 @@ Please find below the code to retrieve blob data from the Spreadsheet control be
134134
135135
{% previewsample "/document-processing/code-snippet/spreadsheet/javascript-es6/save-as-blobdata-cs1" %}
136136
137+
### Save as JSON
138+
139+
serializes the current workbook into a JSON object that contains sheets, cell data, styles, formulas, and workbook settings. you can store that object and later restore it with openFromJson.
140+
141+
The [saveAsJson](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#saveasjson) method converts the entire Spreadsheet workbook into a JSON object. This JSON includes sheets, cell values, formulas, styles, formatting, charts, and other workbook settings. It acts as a complete representation of the current spreadsheet state, which can be stored, sent to a server, or later restored using openFromJson.
142+
143+
saveAsJson is used to capture the full state of the Spreadsheet in a simple, structured format. Instead of creating an Excel file immediately, the workbook is converted into JSON, which is easier for applications to handle. This makes it useful when you want to store spreadsheet data temporarily, save it to a database, send it through an API, or allow another system to process or modify the data before creating an Excel file. It also helps when you want to restore the same workbook later without losing styles, formulas, or layout.
144+
145+
The main benefit for users is that the Spreadsheet state can be saved quickly without waiting for the server to generate an Excel file. Because JSON is lightweight, it can be stored or transferred very fast, making the save operation feel smoother. When the JSON is loaded again, the workbook looks exactly as before, which gives users a consistent experience. This also reduces errors and makes the application more responsive during save operations.
146+
147+
148+
The following code snippet demonstrates saveAsJson method:
149+
150+
{% tabs %}
151+
{% highlight js tabtitle="app.jsx" %}
152+
{% include code-snippet/spreadsheet/react/save-as-json-cs1/app/app.jsx %}
153+
{% endhighlight %}
154+
{% highlight ts tabtitle="app.tsx" %}
155+
{% include code-snippet/spreadsheet/react/save-as-json-cs1/app/app.tsx %}
156+
{% endhighlight %}
157+
{% endtabs %}
158+
159+
{% previewsample "/document-processing/code-snippet/spreadsheet/react/save-as-json-cs1" %}
160+
137161
### Save Excel files to a server
138162
139163
By default, the Spreadsheet control saves the Excel file and downloads it to the local file system. If you want to save an Excel file to a server location, you need to configure the server endpoint to convert the spreadsheet data into a file stream and save it to the server location. To do this, first, on the client side, you must convert the spreadsheet data into `JSON` format using the [saveAsJson](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#saveasjson) method and send it to the server endpoint. On the server endpoint, you should convert the received spreadsheet `JSON` data into a file stream using `Syncfusion.EJ2.Spreadsheet.AspNet.Core`, then convert the stream into an Excel file, and finally save it to the server location.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as React from 'react';
2+
import { createRoot } from 'react-dom/client';
3+
import { SpreadsheetComponent } from '@syncfusion/ej2-react-spreadsheet';
4+
import { jsonData } from './datasource';
5+
6+
function App() {
7+
const spreadsheetRef = React.useRef(null);
8+
9+
const handleOpenFromJson = React.useCallback(() => {
10+
if (!spreadsheetRef.current) return;
11+
try {
12+
spreadsheetRef.current.openFromJson({ file: jsonData });
13+
} catch (e) {
14+
console.error('Failed to open from JSON', e);
15+
alert('Failed to open from JSON.');
16+
}
17+
}, []);
18+
19+
return (
20+
<div className="control-pane">
21+
<div className="control-section spreadsheet-control">
22+
<div style={{ padding: '8px 0' }}>
23+
<button className="e-btn e-primary" onClick={handleOpenFromJson}>
24+
Open from JSON
25+
</button>
26+
</div>
27+
<div>
28+
<SpreadsheetComponent id="spreadsheet" ref={spreadsheetRef} />
29+
</div>
30+
</div>
31+
</div>
32+
);
33+
}
34+
35+
export default App;
36+
37+
const root = createRoot(document.getElementById('root'));
38+
root.render(<App />);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as React from 'react';
2+
import { createRoot } from 'react-dom/client';
3+
import { SpreadsheetComponent } from '@syncfusion/ej2-react-spreadsheet';
4+
import { jsonData } from './datasource';
5+
6+
function App(): React.ReactElement {
7+
const spreadsheetRef = React.useRef<SpreadsheetComponent | null>(null);
8+
9+
const handleOpenFromJson = React.useCallback((): void => {
10+
if (!spreadsheetRef.current) return;
11+
try {
12+
spreadsheetRef.current.openFromJson({ file: jsonData });
13+
} catch (e) {
14+
console.error('Failed to open from JSON', e);
15+
alert('Failed to open from JSON.');
16+
}
17+
}, []);
18+
19+
return (
20+
<div className="control-pane">
21+
<div className="control-section spreadsheet-control">
22+
<div style={{ padding: '8px 0' }}>
23+
<button className="e-btn e-primary" onClick={handleOpenFromJson}>
24+
Open from JSON
25+
</button>
26+
</div>
27+
<div>
28+
<SpreadsheetComponent id="spreadsheet" ref={spreadsheetRef} />
29+
</div>
30+
</div>
31+
</div>
32+
);
33+
}
34+
35+
export default App;
36+
37+
const root = createRoot(document.getElementById('root')!);
38+
root.render(<App />);

0 commit comments

Comments
 (0)