diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 7a49deccd..951d3106c 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -1983,6 +1983,9 @@
  • Azure App Service (Linux)
  • +
  • + Azure Functions v4 +
  • Cloud Storage diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img1.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img1.png new file mode 100644 index 000000000..3ae6e9dc6 Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img1.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img10.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img10.png new file mode 100644 index 000000000..438aa22f4 Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img10.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img11.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img11.png new file mode 100644 index 000000000..c2565d820 Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img11.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img12.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img12.png new file mode 100644 index 000000000..11a0d28da Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img12.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img13.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img13.png new file mode 100644 index 000000000..29003a74a Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img13.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img2.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img2.png new file mode 100644 index 000000000..3bc1d07c3 Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img2.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img3.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img3.png new file mode 100644 index 000000000..50c12c77d Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img3.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img4.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img4.png new file mode 100644 index 000000000..64f2cf984 Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img4.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img5.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img5.png new file mode 100644 index 000000000..377055340 Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img5.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img6.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img6.png new file mode 100644 index 000000000..b8fc197a2 Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img6.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img7.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img7.png new file mode 100644 index 000000000..bf881413f Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img7.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img8.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img8.png new file mode 100644 index 000000000..b153b4578 Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img8.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img9.png b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img9.png new file mode 100644 index 000000000..fa8e5d36e Binary files /dev/null and b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img9.png differ diff --git a/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/loading-and-saving-excel-files-in-azure-functions-v4.md b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/loading-and-saving-excel-files-in-azure-functions-v4.md new file mode 100644 index 000000000..124a989cb --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/Loading-and-Saving/loading-and-saving-excel-files-in-azure-functions-v4.md @@ -0,0 +1,174 @@ +--- +title: Loading and Saving Excel in Azure Functions v4 | Syncfusion +description: Explains how to load and save an Excel files in Azure Functions v4 using Syncfusion Excel library. +platform: document-processing +control: XlsIO +documentation: UG +--- +# Loading and Saving Excel files in Azure Functions v4 + +Syncfusion® XlsIO is a [.NET Excel library](https://www.syncfusion.com/document-processing/excel-framework/net) can be used to create, read, edit Excel files in Azure Functions v4. + +## Steps to Load and Save an Excel document in Azure Functions v4 + +The below steps illustrates loading and saving a simple Invoice formatted Excel document in Azure Functions v4. + +Step 1: Create a new Azure Functions project. + +![Create an Azure Functions project in visual studio](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img1.png) + +Step 2: Name the project. + +![Name the project](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img2.png) + +Step 3: Select the framework and click **Create** button. + +![Framework version](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img3.png) + +Step 4: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org). + +![Install Syncfusion.XlsIO.Net.Core Nuget Package](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img4.png) + +N> Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion® license key in your applications to use our components. + +Step 5: Include the following namespaces in the Function1.cs file. + +{% tabs %} +{% highlight c# tabtitle="C#" %} +using Syncfusion.XlsIO; +{% endhighlight %} +{% endtabs %} + +Step 6: Add the following code snippet in **Run** method of **Function1** class to perform **Loading and Saving Excel files** in Azure Functions v4. + +{% tabs %} +{% highlight c# tabtitle="C#" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + //Load an existing Excel document + FileStream inputStream = new FileStream("Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + + //Access first worksheet from the workbook + IWorksheet worksheet = workbook.Worksheets[0]; + + //Set Text in cell A3 + worksheet.Range["A3"].Text = "Hello World"; + + MemoryStream outputStream = new MemoryStream(); + workbook.SaveAs(outputStream); + outputStream.Position = 0; + + //Set headers + response.Headers.Add("Content-Disposition", "attachment; filename=Output.xlsx"); + + //Set the content type as Excel document mime type + response.Headers.Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + + await response.Body.WriteAsync(outputStream.ToArray()); + + //Return the response with output Excel document stream + return response; +} +{% endhighlight %} +{% endtabs %} + +Step 7: Right-click the project and select **Publish** option. + +![Publish](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img5.png) + +Step 8: Select the publish target as **Azure**. + +![Add a Publish Profile](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img6.png) + +Step 9: Select the Specific target as **Azure Function App (Windows)**. + +![Select the publish target](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img7.png) + +Step 10: Select the **Create new** button. + +![Click create new option](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img8.png) + +Step 11: Click the **Create** button to proceed with creation. + +![Hosting](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img9.png) + +Step 12: Click the **Finish** button to finalize the **Azure Function** creation. + +![Creating app service](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img10.png) + +Step 13: Click **Close** button. + +![Profile created](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img11.png) + +Step 14: Click the **Publish** button. + +![Click Publish Button](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img12.png) + +Step 15: Publish has been succeeded. + +![Publish succeeded](Loading-and-Saving_images/Loadind-and-Saving-Azure-Functions-v4_img13.png) + +Step 16: Now, go to Azure portal and select the App Services. After running the service, click **Get function URL by copying it**. Then, paste it in the below client sample (which will request the Azure Functions, to perform **Loading and Saving Excel files** using the template Excel document). You will get the output Excel document as follows. + +![Output File](Loading-and-Saving_images/Loading-and-Saving_images_img30.png) + +## Steps to post the request to Azure Functions + +Step 1: Create a console application to request the Azure Functions API. + +Step 2: Add the following code snippet into **Main** method to post the request to Azure Functions with template Excel document and get the resultant Excel document. +{% tabs %} +{% highlight c# tabtitle="C#" %} +//Reads the template Excel document. +FileStream excelStream = new FileStream("../../Sample.xlsx", FileMode.Open, FileAccess.Read); +excelStream.Position = 0; + +//Saves the Excel document in memory stream. +MemoryStream inputStream = new MemoryStream(); +excelStream.CopyTo(inputStream); +inputStream.Position = 0; + +try +{ + Console.WriteLine("Please enter your Azure Functions URL :"); + string functionURL = Console.ReadLine(); + + //Create HttpWebRequest with hosted azure functions URL + HttpWebRequest req = (HttpWebRequest)WebRequest.Create(functionURL); + + //Set request method as POST + req.Method = "POST"; + + //Get the request stream to save the Excel document stream + Stream stream = req.GetRequestStream(); + + //Write the Excel document stream into request stream + stream.Write(inputStream.ToArray(), 0, inputStream.ToArray().Length); + + //Gets the responce from the Azure Functions + HttpWebResponse res = (HttpWebResponse)req.GetResponse(); + + //Saves the Excel stream + FileStream outStream = File.Create("Sample.xlsx"); + res.GetResponseStream().CopyTo(outStream); + + //Dispose the streams + inputStream.Dispose(); + outStream.Dispose(); +} +catch (Exception ex) +{ + throw; +} +{% endhighlight %} +{% endtabs %} + +A complete working example of how to load and save an Excel document in Azure Functions v4 in C# is present on [this GitHub page](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Loading%20and%20Saving/Azure/Azure%20Functions%20v4/Loading%20and%20Saving). + +Click [here](https://www.syncfusion.com/document-processing/excel-framework/net-core) to explore the rich set of Syncfusion® Excel library (XlsIO) features. + +An online sample link to [create an Excel document](https://ej2.syncfusion.com/aspnetcore/Excel/Create#/material3) in ASP.NET Core. \ No newline at end of file