diff --git a/ej2-asp-core-mvc/code-snippet/spreadsheet/open-from-blob/opencontroller.cs b/ej2-asp-core-mvc/code-snippet/spreadsheet/open-from-blob/opencontroller.cs new file mode 100644 index 0000000000..1ac50f75a2 --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/spreadsheet/open-from-blob/opencontroller.cs @@ -0,0 +1,11 @@ +public IActionResult Open(IFormCollection openRequest) +{ + OpenRequest open = new OpenRequest(); + open.File = openRequest.Files[0]; + return Content(Workbook.Open(open)); +} + +public void Save(SaveSettings saveSettings) +{ + Workbook.Save(saveSettings); +} \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/spreadsheet/open-from-blob/razor b/ej2-asp-core-mvc/code-snippet/spreadsheet/open-from-blob/razor new file mode 100644 index 0000000000..5c8f32eadc --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/spreadsheet/open-from-blob/razor @@ -0,0 +1,17 @@ +@Html.EJS().Spreadsheet("spreadsheet").OpenUrl("Open").SaveUrl("Save").Created("created").Render() + + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/spreadsheet/open-from-blob/tagHelper b/ej2-asp-core-mvc/code-snippet/spreadsheet/open-from-blob/tagHelper new file mode 100644 index 0000000000..1152c5e127 --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/spreadsheet/open-from-blob/tagHelper @@ -0,0 +1,19 @@ + + + + + diff --git a/ej2-asp-core-mvc/code-snippet/spreadsheet/save-as-blob/razor b/ej2-asp-core-mvc/code-snippet/spreadsheet/save-as-blob/razor new file mode 100644 index 0000000000..e6b1b37008 --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/spreadsheet/save-as-blob/razor @@ -0,0 +1,22 @@ +@Html.EJS().Spreadsheet("spreadsheet").OpenUrl("Open").SaveUrl("Save").BeforeSave("beforeSave").SaveComplete("saveComplete").Sheets(sheet => { + sheet.Name("Price Details").Ranges(ranges => { + ranges.DataSource((IEnumerable)ViewBag.DefaultData).StartCell("A1").Add(); + }).Columns(column => { + column.Width(130).Add(); + column.Width(100).Add(); + column.Width(100).Add(); + }).Add(); +}).Render() + + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/spreadsheet/save-as-blob/savecontroller.cs b/ej2-asp-core-mvc/code-snippet/spreadsheet/save-as-blob/savecontroller.cs new file mode 100644 index 0000000000..1b49d84138 --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/spreadsheet/save-as-blob/savecontroller.cs @@ -0,0 +1,31 @@ +public IActionResult Open(IFormCollection openRequest) +{ + OpenRequest open = new OpenRequest(); + open.File = openRequest.Files[0]; + return Content(Workbook.Open(open)); +} + +public void Save(SaveSettings saveSettings) +{ + Workbook.Save(saveSettings); +} + +public IActionResult Index() + { + List defaultData = new List() + { + new { Item Name= "Casual Shoes", Date= "02/14/2014", Time= "11:34:32 AM", Quantity= "10", Price= "20", Amount= "200", Discount= "1", Profit= "10" }, + new { Item Name= "Sports Shoes", Date= "06/11/2014", Time= "05:56:32 AM", Quantity= "20", Price= "30", Amount= "600", Discount= "5", Profit= "50" }, + new { Item Name= "Formal Shoes", Date= "07/27/2014", Time= "03:32:44 AM", Quantity= "20", Price= "15", Amount= "300", Discount= "7", Profit= "27" }, + new { Item Name= "Sandals & Floaters", Date= "11/21/2014", Time= "06:23:54 AM", Quantity= "15", Price= "20", Amount= "300", Discount= "11", Profit= "67" }, + new { Item Name= "Flip- Flops & Slippers", Date= "06/23/2014", Time= "12:43:59 AM", Quantity= "30", Price= "10", Amount= "300", Discount= "10", Profit= "70" }, + new { Item Name= "Sneakers", Date= "07/22/2014", Time= "10:55:53 AM", Quantity= "40", Price= "20", Amount= "800", Discount= "13", Profit= "66" }, + new { Item Name= "Running Shoes", Date= "02/04/2014", Time= "03:44:34 AM", Quantity= "20", Price= "10", Amount= "200", Discount= "3", Profit= "14" }, + new { Item Name= "Loafers", Date= "11/30/2014", Time= "03:12:52 AM", Quantity= "31", Price= "10", Amount= "310", Discount= "6", Profit= "29" }, + new { Item Name= "Cricket Shoes", Date= "07/09/2014", Time= "11:32:14 AM", Quantity= "41", Price= "30", Amount= "1210", Discount= "12", Profit= "166" }, + new { Item Name= "T-Shirts", Date= "10/31/2014", Time= "12:01:44 AM", Quantity= "50", Price= "10", Amount= "500", Discount= "9", Profit= "55" } + }; + ViewBag.DefaultData = defaultData; + return View(); + + } \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/spreadsheet/save-as-blob/tagHelper b/ej2-asp-core-mvc/code-snippet/spreadsheet/save-as-blob/tagHelper new file mode 100644 index 0000000000..6094f91cdf --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/spreadsheet/save-as-blob/tagHelper @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/ej2-asp-core-mvc/spreadsheet/open-save.md b/ej2-asp-core-mvc/spreadsheet/open-save.md index 50026e0793..da5797b17a 100644 --- a/ej2-asp-core-mvc/spreadsheet/open-save.md +++ b/ej2-asp-core-mvc/spreadsheet/open-save.md @@ -247,6 +247,35 @@ The following code example shows how to open the spreadsheet data as base64 stri {% endtabs %} {% endif %} +### To open an excel file from blob data + +By default, the Spreadsheet control provides an option to browse files from the local file system and open them within the control. If you want to open an Excel file from blob data, you need to fetch the blob data from the server or another source and convert this blob data into a `File` object. Then, you can use the `open` method in the Spreadsheet control to load that `File` object. + +Please find the code to fetch the blob data and load it into the Spreadsheet control below. + +{% if page.publishingplatform == "aspnet-core" %} + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} +{% include code-snippet/spreadsheet/open-from-blob/tagHelper %} +{% endhighlight %} +{% highlight c# tabtitle="OpenController.cs" %} +{% include code-snippet/spreadsheet/open-from-blob/opencontroller.cs %} +{% endhighlight %} +{% endtabs %} + +{% elsif page.publishingplatform == "aspnet-mvc" %} + +{% tabs %} +{% highlight razor tabtitle="CSHTML" %} +{% include code-snippet/spreadsheet/open-from-blob/razor %} +{% endhighlight %} +{% highlight c# tabtitle="OpenController.cs" %} +{% include code-snippet/spreadsheet/open-from-blob/opencontroller.cs %} +{% endhighlight %} +{% endtabs %} +{% endif %} + ### External workbook confirmation dialog 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 +521,35 @@ The following code example shows how to save the spreadsheet data as base64 stri {% endtabs %} {% endif %} +### To save an excel file as blob data + +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` event of the spreadsheet. Subsequently, you will receive the spreadsheet data as a blob in the `saveComplete` event. You can then post the blob data to the server endpoint for saving. + +Please find below the code to retrieve blob data from the Spreadsheet control below. + +{% if page.publishingplatform == "aspnet-core" %} + +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} +{% include code-snippet/spreadsheet/save-as-blob/tagHelper %} +{% endhighlight %} +{% highlight c# tabtitle="SaveController.cs" %} +{% include code-snippet/spreadsheet/save-as-blob/savecontroller.cs %} +{% endhighlight %} +{% endtabs %} + +{% elsif page.publishingplatform == "aspnet-mvc" %} + +{% tabs %} +{% highlight razor tabtitle="CSHTML" %} +{% include code-snippet/spreadsheet/save-as-blob/razor %} +{% endhighlight %} +{% highlight c# tabtitle="SaveController.cs" %} +{% include code-snippet/spreadsheet/save-as-blob/savecontroller.cs %} +{% endhighlight %} +{% endtabs %} +{% endif %} + ### Supported file formats The following list of Excel file formats are supported in Spreadsheet: