You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Document-Processing/Excel/Spreadsheet/React/open-excel-files.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ The following sample shows the `Open` option by using the [`openUrl`](https://ej
39
39
40
40
Please find the below table for the [beforeOpen](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#beforeopen) event arguments.
Copy file name to clipboardExpand all lines: Document-Processing/Excel/Spreadsheet/React/save-excel-files.md
+92-88Lines changed: 92 additions & 88 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ layout: post
3
3
title: Save Excel Files in React Spreadsheet component | Syncfusion
4
4
description: Learn here all about Saving Excel files in Syncfusion React Spreadsheet component of Syncfusion Essential JS 2 and more.
5
5
platform: document-processing
6
-
control: Open
6
+
control: Save
7
7
documentation: ug
8
8
---
9
9
@@ -24,20 +24,26 @@ For a quick walkthrough on how the save functionality works, refer to the follow
24
24
25
25
In user interface, you can save Spreadsheet data as Excel document by clicking `File > Save As` menu item in ribbon.
26
26
27
-
The following sample shows the `Save` option by using the [`saveUrl`](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#saveurl) property in the Spreadsheet control. You can also use the [`beforeSave`](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#beforesave) event to customize or cancel the save action which gets triggered before saving the Spreadsheet as an Excel file.
27
+
The following sample shows the `Save` option by using the [`saveUrl`](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#saveurl) property in the Spreadsheet control. You can also use the [`beforeSave`](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#beforesave) event to customize or cancel the save action which gets triggered before saving the Spreadsheet as an Excel file.
28
28
29
29
{% tabs %}
30
-
{% highlight ts tabtitle="index.ts" %}
31
-
{% include code-snippet/spreadsheet/javascript-es6/open-save-cs5/index.ts %}
30
+
{% highlight js tabtitle="app.jsx" %}
31
+
{% include code-snippet/spreadsheet/react/open-save-cs5/app/app.jsx %}
32
+
{% endhighlight %}
33
+
{% highlight ts tabtitle="app.tsx" %}
34
+
{% include code-snippet/spreadsheet/react/open-save-cs5/app/app.tsx %}
32
35
{% endhighlight %}
33
-
{% highlight html tabtitle="index.html" %}
34
-
{% include code-snippet/spreadsheet/javascript-es6/open-save-cs5/index.html %}
36
+
{% highlight js tabtitle="datasource.jsx" %}
37
+
{% include code-snippet/spreadsheet/react/open-save-cs5/app/datasource.jsx %}
38
+
{% endhighlight %}
39
+
{% highlight ts tabtitle="datasource.tsx" %}
40
+
{% include code-snippet/spreadsheet/react/open-save-cs5/app/datasource.tsx %}
Please find the below table for the [`beforeSave`](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#beforesave) event arguments.
41
47
42
48
|**Parameter**|**Type**|**Description**|
43
49
| ----- | ----- | ----- |
@@ -51,14 +57,14 @@ Please find the below table for the [`beforeSave`](https://ej2.syncfusion.com/do
51
57
52
58
> * Use `Ctrl + S` keyboard shortcut to save the Spreadsheet data as Excel file.
53
59
54
-
> * The default value of [allowSave](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#allowsave) property is `true`. For demonstration purpose, we have showcased the [allowSave](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#allowsave) property in previous code snippet.
60
+
> * The default value of [allowSave](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#allowsave) property is `true`. For demonstration purpose, we have showcased the [allowSave](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#allowsave) property in previous code snippet.
55
61
> * Demo purpose only, we have used the online web service url link.
56
62
57
63
## Save Excel files programmatically
58
64
59
65
To save Excel files programmatically in the Spreadsheet, you can use the [`save`](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#save) method of the Spreadsheet component. Before invoking this method, ensure that the [`saveUrl`](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#saveurl) property is properly configured, as it is required for processing and generating the file on the server.
60
66
61
-
Please find the below table for the [`save`](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#save) method arguments.
67
+
Please find the below table for the [`save`](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#save) method arguments.
The following file formats are supported when saving the Spreadsheet component:
@@ -119,20 +124,20 @@ The following file formats are supported when saving the Spreadsheet component:
119
124
120
125
### Save Excel files as Blob
121
126
122
-
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 as blob data, you need to set `needBlobData` property to **true** and `isFullPost` property to **false** in the [beforeSave](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#beforesave) event of the spreadsheet. Subsequently, you will receive the spreadsheet data as a blob in the [saveComplete](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#savecomplete) event. You can then post the blob data to the server endpoint for saving.
127
+
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 as blob data, you need to set `needBlobData` property to **true** and `isFullPost` property to **false** in the [beforeSave](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#beforesave) event of the spreadsheet. Subsequently, you will receive the spreadsheet data as a blob in the [saveComplete](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#savecomplete) event. You can then post the blob data to the server endpoint for saving.
123
128
124
129
Please find below the code to retrieve blob data from the Spreadsheet control below.
125
130
126
131
{% tabs %}
127
-
{% highlight ts tabtitle="index.ts" %}
128
-
{% include code-snippet/spreadsheet/javascript-es6/save-as-blobdata-cs1/index.ts %}
132
+
{% highlight js tabtitle="app.jsx" %}
133
+
{% include code-snippet/spreadsheet/react/save-as-blobdata-cs1/app/app.jsx %}
129
134
{% endhighlight %}
130
-
{% highlight html tabtitle="index.html" %}
131
-
{% include code-snippet/spreadsheet/javascript-es6/save-as-blobdata-cs1/index.html %}
135
+
{% highlight ts tabtitle="app.tsx" %}
136
+
{% include code-snippet/spreadsheet/react/save-as-blobdata-cs1/app/app.tsx %}
@@ -155,7 +160,7 @@ The following example demonstrates how to save a workbook as JSON from the Sprea
155
160
156
161
### Save Excel files to a server
157
162
158
-
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.
163
+
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/react/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.
159
164
160
165
**Client Side**:
161
166
@@ -219,78 +224,77 @@ Before proceeding with the save process, you should deploy the spreadsheet open/
219
224
220
225
[How to deploy a spreadsheet open and save web API service to AWS Lambda](https://support.syncfusion.com/kb/article/17184/how-to-deploy-a-spreadsheet-open-and-save-web-api-service-to-aws-lambda)
221
226
222
-
After deployment, you will get the AWS service URL for the open and save actions. Before saving the Excel file with this hosted save URL, you need to prevent the default save action to avoid getting a corrupted excel file on the client end. The save service returns the file stream as a result to the client, which can cause the file to become corrupted. To prevent this, set the `args.cancel` value to `true` in the [`beforeSave`](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#beforesave) event. After that, convert the spreadsheet data into JSON format using the [saveAsJson](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#saveasjson) method in the `beforeSave` event and send it to the save service endpoint URL using a fetch request.
227
+
After deployment, you will get the AWS service URL for the open and save actions. Before saving the Excel file with this hosted save URL, you need to prevent the default save action to avoid getting a corrupted excel file on the client end. The save service returns the file stream as a result to the client, which can cause the file to become corrupted. To prevent this, set the `args.cancel` value to `true` in the [`beforeSave`](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#beforesave) event. After that, convert the spreadsheet data into JSON format using the [saveAsJson](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#saveasjson) method in the `beforeSave` event and send it to the save service endpoint URL using a fetch request.
223
228
224
229
On the server side, the save service will take the received JSON data, pass it to the workbook `Save` method, and return the result as a base64 string. The fetch success callback will receive the Excel file in base64 string format on the client side. Finally, you can then convert the base64 string back to a file on the client end to obtain a non-corrupted Excel file.
225
230
226
231
The following code example shows how to save an Excel file using a hosted web service in AWS Lambda, as mentioned above.
@@ -305,20 +309,20 @@ public string Save([FromForm]SaveSettings saveSettings)
305
309
306
310
In the Spreadsheet component, there is currently no direct option to save data as a `Base64` string. You can achieve this by saving the Spreadsheet data as blob data and then converting that saved blob data to a `Base64` string using `FileReader`.
307
311
308
-
> You can get the Spreadsheet data as blob in the [saveComplete](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#savecomplete) event when you set the `needBlobData` as **true** and `isFullPost` as **false** in the [beforeSave](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#beforesave) event.
312
+
> You can get the Spreadsheet data as blob in the [saveComplete](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#savecomplete) event when you set the `needBlobData` as **true** and `isFullPost` as **false** in the [beforeSave](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#beforesave) event.
309
313
310
314
The following code example shows how to save the spreadsheet data as base64 string.
311
315
312
316
{% tabs %}
313
-
{% highlight ts tabtitle="index.ts" %}
314
-
{% include code-snippet/spreadsheet/javascript-es6/base-64-string/index.ts %}
317
+
{% highlight js tabtitle="app.jsx" %}
318
+
{% include code-snippet/spreadsheet/react/base-64-string/app/app.jsx %}
315
319
{% endhighlight %}
316
-
{% highlight html tabtitle="index.html" %}
317
-
{% include code-snippet/spreadsheet/javascript-es6/base-64-string/index.html %}
320
+
{% highlight ts tabtitle="app.tsx" %}
321
+
{% include code-snippet/spreadsheet/react/base-64-string/app/app.tsx %}
0 commit comments