From a18e21f98a72e78d77264955fe26012a8ef33a2b Mon Sep 17 00:00:00 2001 From: gopinathan-sf4977 Date: Wed, 27 Aug 2025 16:53:05 +0530 Subject: [PATCH] 978242: Added UG for MVC --- .../Spreadsheet/ASP-NET-MVC/open-save.md | 72 +++++++++++++++++-- .../ASP-NET-MVC/performance-best-practices.md | 6 +- .../open-save-cs1/openSaveController.cs | 23 ++++++ .../ASP-NET-MVC/open-save-cs1/razor | 24 +++++++ .../ASP-NET-MVC/open-save-cs1/tagHelper | 25 +++++++ 5 files changed, 142 insertions(+), 8 deletions(-) create mode 100644 Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/openSaveController.cs create mode 100644 Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/razor create mode 100644 Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/tagHelper diff --git a/Document-Processing/Excel/Spreadsheet/ASP-NET-MVC/open-save.md b/Document-Processing/Excel/Spreadsheet/ASP-NET-MVC/open-save.md index 7d94adec7..c97ae4643 100644 --- a/Document-Processing/Excel/Spreadsheet/ASP-NET-MVC/open-save.md +++ b/Document-Processing/Excel/Spreadsheet/ASP-NET-MVC/open-save.md @@ -40,6 +40,7 @@ Find the below table for the beforeOpen event arguments. | file | FileList or string or File | To get the file stream. `FileList` - contains length and item index.
`File` - specifies the file lastModified and file name. | | cancel | boolean | To prevent the open operation. | | requestData | object | To provide the Form data. | +| parseOptions | WorkbookParseOptions | Specifies options to control how the Excel file is loaded. You can skip specific properties to optimize performance. | N> * Use `Ctrl + O` keyboard shortcut to open Excel documents.
* The default value of the [allowOpen](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Spreadsheet.Spreadsheet.html#Syncfusion_EJ2_Spreadsheet_Spreadsheet_AllowOpen) property is `true`. For demonstration purpose, we have showcased the [allowOpen](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Spreadsheet.Spreadsheet.html#Syncfusion_EJ2_Spreadsheet_Spreadsheet_AllowOpen) property in previous code snippet. @@ -262,22 +263,41 @@ The following code snippet demonstrates how to configure the deserialization opt ### Improving Excel file open performance with parsing options -Opening large Excel files into the EJ2 Spreadsheet control can sometimes lead to slower performance and increased memory usage. This is often caused by the processing of additional elements such as styles and number formats—even when the actual data content is minimal. For example, an Excel file with only a small amount of data but a large number of styled or formatted empty cells can significantly impact load time and memory consumption. +Opening large Excel files into the EJ2 Spreadsheet Control can sometimes lead to slower performance and increased memory usage. This is often caused by the processing of additional elements such as styles, number formats, formulas, validations, conditional formats, merged cells, charts, and images—even when the actual data content is minimal. For example, an Excel file with only a small amount of data but a large number of styled or formatted empty cells can significantly impact load time and memory consumption. -To address this, we've introduced parsing options that allow users to selectively skip non-essential features during the open process. By enabling options like `IgnoreStyle` and `IgnoreFormat`, you can reduce the amount of data processed, resulting in: +To address this, we've introduced parsing options that allow users to selectively skip non-essential properties during the open process. By enabling parse options, you can reduce the amount of data processed, resulting in: * Faster load times * Lower memory usage * Smaller JSON responses These enhancements are especially beneficial for users working with large or complex Excel files, offering a more efficient and responsive experience. -> **Note:** These options are ideal when styles and number formats are not critical to your use case and the focus is on loading the actual data efficiently. +Please find the table below for available parsing options +| Option | Description | +|-------------------------|--------------------------------------------------------------------| +| `IgnoreStyle` | Skips cell styling such as font, color, borders, and alignment. | +| `IgnoreFormat` | Skips number formatting rules (e.g., currency, date formats). | +| `IgnoreFormula` | Skips formula cells and imports only the last calculated values. | +| `IgnoreValidation` | Skips data validation rules. | +| `IgnoreConditionalFormat` | Skips conditional formatting rules. | +| `IgnoreMergedCell` | Skips merged cell information. | +| `IgnoreChart` | Skips embedded chart objects. | +| `IgnoreImage` | Skips embedded images. | +--- + +> **Note:** These options are ideal when styles, formats, formulas, and other visual elements are not critical to your use case and the focus is on loading the actual data efficiently. + +**Ways to Configure Parsing Option** + +You can configure parsing options in two ways: -The code example below demonstrates how to configure the `IgnoreStyle` and `IgnoreFormat` parsing options on the `server-side`. +**1. Server-Side Configuration:** +Set the parsing options directly in the `server-side` when handling the Excel file open request. + +The code example below demonstrates how to configure parse options on the `server-side`. **Code Snippet:** -**Server-Side Configuration:** ```csharp public IActionResult Open(IFormCollection openRequest) { @@ -285,13 +305,52 @@ public IActionResult Open(IFormCollection openRequest) ... open.ParseOptions = new WorkbookParseOptions() { IgnoreStyle = true, - IgnoreFormat = true + IgnoreFormat = true, + IgnoreFormula = true, + IgnoreValidation = true, + IgnoreConditionalFormat = true, + IgnoreMergedCell = true, + IgnoreChart = true, + IgnoreImage = true }; ... return Content(Workbook.Open(open)); } ``` +**2. Client-Side Configuration Using beforeOpen Event:** +Use the beforeOpen event in the EJ2 Spreadsheet Control to pass parsing options before the file is opened. These options are then handled on the server side during deserialization. + +The code example below demonstrates how to configure parse options on the `client-side`. + +{% tabs %} +{% highlight razor tabtitle="CSHTML" %} +{% include code-snippet/excel/spreadsheet/asp-net-mvc/open-save-cs1/razor %} +{% endhighlight %} +{% highlight c# tabtitle="OpenSaveController.cs" %} +{% include code-snippet/excel/spreadsheet/asp-net-mvc/open-save-cs1/openSaveController.cs %} +{% endhighlight %} +{% endtabs %} + +To receive and apply the parsing options passed from the client, add deserialization logic in the server-side open request handler + +**Code Snippet:** +```csharp +public IActionResult Open(IFormCollection openRequest) +{ + OpenRequest open = new OpenRequest(); + ... + // Assigning the parse options to control which properties to skip while loading Excel files. + var parseOptions = openRequest["ParseOptions"]; + if (!string.IsNullOrEmpty(parseOptions)) + { + open.ParseOptions = System.Text.Json.JsonSerializer.Deserialize * Use `Ctrl + S` keyboard shortcut to save the Spreadsheet data as Excel file.
* The default value of [allowSave](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Spreadsheet.Spreadsheet.html#Syncfusion_EJ2_Spreadsheet_Spreadsheet_AllowSave) property is `true`. For demonstration purpose, we have showcased the [allowSave](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Spreadsheet.Spreadsheet.html#Syncfusion_EJ2_Spreadsheet_Spreadsheet_AllowSave) property in previous code snippet. diff --git a/Document-Processing/Excel/Spreadsheet/ASP-NET-MVC/performance-best-practices.md b/Document-Processing/Excel/Spreadsheet/ASP-NET-MVC/performance-best-practices.md index 1bf79487d..ba755ff8f 100644 --- a/Document-Processing/Excel/Spreadsheet/ASP-NET-MVC/performance-best-practices.md +++ b/Document-Processing/Excel/Spreadsheet/ASP-NET-MVC/performance-best-practices.md @@ -77,9 +77,11 @@ public IActionResult Open(IFormCollection openRequest) ### Optimize Excel open with parsing options -To improve performance when opening large Excel files, use parsing options like `IgnoreStyle` and `IgnoreFormat` to skip unnecessary styles and formats. This reduces memory usage, speeds up loading, and minimizes JSON size—especially helpful for files with many styled but empty cells. +To improve performance when opening large Excel files, use parsing options to skip non-essential properties during import. These options help reduce memory usage, speed up loading, and minimize JSON size—especially useful for files with complex formatting or large datasets. -To learn how to configure these parsing options, please refer to the UG section below. +By configuring the parse options, you can load Excel files into the Spreadsheet while retaining only the necessary content. This ensures efficient handling of large or high-memory files without compromising essential data. + +To learn how to configure the parsing options, please refer to the UG section below. * [Configure Parsing Options](./open-save#improving-excel-file-open-performance-with-parsing-options) ## How to improve performance on formula calculation in Spreadsheet? diff --git a/Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/openSaveController.cs b/Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/openSaveController.cs new file mode 100644 index 000000000..b73fe94d7 --- /dev/null +++ b/Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/openSaveController.cs @@ -0,0 +1,23 @@ +using Syncfusion.EJ2.Spreadsheet; +using System.Web.Mvc; + +namespace YourProjectName.Controllers +{ + public class HomeController : Controller + { + public ActionResult Open(OpenRequest openRequest) + { + // The openRequest object is automatically populated with the file data + // and the parseOptions set in the client-side beforeOpen event. + // Workbook.Open processes the request and returns the spreadsheet data as JSON. + return Content(Workbook.Open(openRequest)); + } + + public ActionResult Save(SaveSettings saveSettings) + { + // Workbook.Save handles the spreadsheet data and returns the file + // to be downloaded by the user. + return Workbook.Save(saveSettings); + } + } +} \ No newline at end of file diff --git a/Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/razor b/Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/razor new file mode 100644 index 000000000..0bf19ce3f --- /dev/null +++ b/Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/razor @@ -0,0 +1,24 @@ +@using Syncfusion.EJ2 + +@* + This sets up the Spreadsheet component with open and save functionality, + pointing to the actions in your HomeController. +*@ +@Html.EJS().Spreadsheet("spreadsheet").OpenUrl("Home/Open").AllowOpen(true).SaveUrl("Home/Save").AllowSave(true).BeforeOpen("beforeOpen").Render() + + \ No newline at end of file diff --git a/Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/tagHelper b/Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/tagHelper new file mode 100644 index 000000000..9e711ff2f --- /dev/null +++ b/Document-Processing/code-snippet/Excel/Spreadsheet/ASP-NET-MVC/open-save-cs1/tagHelper @@ -0,0 +1,25 @@ +@using Syncfusion.EJ2 + +@* + This uses Tag Helpers to set up the Spreadsheet component. + The openUrl, saveUrl, and beforeOpen event are configured just like in the Razor example. +*@ + + + + \ No newline at end of file