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: ej2-asp-core-mvc/spreadsheet/open-save.md
+133Lines changed: 133 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -247,6 +247,67 @@ The following code example shows how to open the spreadsheet data as base64 stri
247
247
{% endtabs %}
248
248
{% endif %}
249
249
250
+
### To open an Excel file located on a server
251
+
252
+
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 as `JSON data`. On the client side, you should use the `openFromJson` method to load that `JSON data` into the Spreadsheet component.
// Processing the Excel file and return the workbook JSON.
268
+
varresult=Workbook.Open(open);
269
+
fileStream.Close();
270
+
returnContent(result);
271
+
}
272
+
273
+
publicclassFileOptions
274
+
{
275
+
publicstringFileName { get; set; } =string.Empty;
276
+
}
277
+
```
278
+
279
+
**Client-side code**:
280
+
281
+
```js
282
+
283
+
// Fetch call to server to load the Excel.
284
+
fetch('https://localhost:{{Your port number}}/Home/Open', {
285
+
method:'POST',
286
+
headers: {
287
+
'Content-Type':'application/json',
288
+
},
289
+
body:JSON.stringify({ FileName:'Sample' }),
290
+
})
291
+
.then((response) =>response.json())
292
+
.then((data) => {
293
+
// Load the JSON data into spreadsheet.
294
+
spreadsheet.openFromJson({ file: data });
295
+
})
296
+
297
+
```
298
+
299
+
You can find the server endpoint code to fetch and process the Excel file in this attachment(https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebApplication1_(1)-880363187).
300
+
301
+
After launching the server endpoint, you need to update the file fetch URL on the client-side sample as shown below.
When you open an excel file that contains external workbook references, you will see a confirmation dialog. This dialog allows you to either continue with the file opening or cancel the operation. This confirmation dialog will appear only if you set the `AllowExternalWorkbook` property value to **false** during the open request, as shown below. This prevents the spreadsheet from displaying inconsistent data.
@@ -492,6 +553,78 @@ The following code example shows how to save the spreadsheet data as base64 stri
492
553
{% endtabs %}
493
554
{% endif %}
494
555
556
+
### To save an Excel file to a server location
557
+
558
+
By default, the spreadsheet 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. On the client side, you must convert the spreadsheet data into `JSON` format using the `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`, convert the stream into an Excel file, and then save it to the server location.
559
+
560
+
**Client-side code**:
561
+
562
+
```js
563
+
564
+
// Convert the spreadsheet workbook to JSON data.
565
+
spreadsheet.saveAsJson().then((json) => {
566
+
constformData=newFormData();
567
+
formData.append('FileName', "Sample");
568
+
formData.append('saveType', 'Xlsx');
569
+
// Passing the JSON data to perform the save operation.
You can find the server endpoint code to save the spreadsheet JSON data as an Excel file in the attached documentation(https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebApplication1_(1)-880363187).
617
+
618
+
After launching the server endpoint, you need to update the file fetch URL on the client-side sample as shown below.
0 commit comments