Articles in this section
Category / Section

How to download Excel document in Azure?

7 mins read

Syncfusion® Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. Using this library, you can create and download Excel documents in the Azure platform.

Steps to download Excel document in Azure platform programmatically:

Prerequisites:

  • Visual Studio 2017 with Azure development.
  • An Azure subscription or a free account

Step 1: Create a new ASP.NET Web application project and add code snippet to create Excel using XlsIO

angular listbox

Create a new ASP.NET web application

1. Install the Syncfusion.XlsIO.Base NuGet package as a reference to your .NET Framework applications from the NuGet.org.

Add XlsIO reference to the project

Install NuGet package

2. Add a new Web Form in the ASP.NET project. Right-click on the project and select Add > New Item and add a Web Form from the list. Name it as MainPage.

3. Add a new button in the MainPage.aspx as shown below.

CSHTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
  <body>
    <form id="form1" runat="server">
       <div>
         <asp:Button ID="Button1" runat="server" Text="Create Document" OnClick="OnButtonClicked" />
       </div>
    </form>
  </body>
</html>

 

4. Include the following namespace in your MainPage.aspx.cs file.

C#

using Syncfusion.XlsIO;

 

VB.NET

Imports Syncfusion.XlsIO

 

5. Include the below code snippet in the click event of the button in MainPage.aspx.cs, to create an Excel file and download it.

C#

// Create an instance of ExcelEngine
using (ExcelEngine excelEngine = new ExcelEngine())
{
  // Set the default application version as Excel 2016
  excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2016;
 
  // Create a workbook with a worksheet
  IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1);
 
  // Access the first worksheet from the workbook instance
  IWorksheet worksheet = workbook.Worksheets[0];
 
  // Insert sample text into cell “A1”
  worksheet.Range["A1"].Text = "Hello World";
 
  // Save the workbook to disk in xlsx format
  workbook.SaveAs("Output.xlsx", Response, ExcelDownloadType.Open, ExcelHttpContentType.Excel2016);
}

 

VB.NET

'Create an instance of ExcelEngine
Using excelEngine As ExcelEngine = New ExcelEngine
 
  'Set the default application version as Excel 2016
  excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2016
 
   'Create a workbook with a worksheet
  Dim workbook As IWorkbook = excelEngine.Excel.Workbooks.Create(1)
 
  'Access the first worksheet from the workbook instance
  Dim worksheet As IWorksheet = workbook.Worksheets(0)
 
  'Insert sample text into cell “A1”
  worksheet.Range("A1").Text = "Hello World"
 
  'Save the workbook to disk in xlsx format
  workbook.SaveAs("Output.xlsx", ExcelSaveType.SaveAsXLS, Response, ExcelDownloadType.PromptDialog)
 
End Using

 

Step 2: Publish the Application to Azure

In the Solution Explorer, right-click on the project name and select Publish.

Publish via Solution Explorer

Publish via Solution Explorer

Or we can go to Build Menu and select Publish myASPApp (your_project_name) to open Publish page.

Publish via Build Menu

Publish via Build Menu

Now select the Microsoft Azure App Service, make sure Create New option is selected and then select Publish.

Publish via Microsoft Azure App Service

Publish via Microsoft Azure App Service

This opens a Create App Service dialog, where we can add all the necessary resources required to run the application in Azure.

Step 3: Sign in to the Azure account

In the Create App Service dialog, select Add an account, and sign in to the Azure subscription. If you're already signed in, select the account containing the desired subscription from the dropdown.

Sign in to Azure account

Step 4: Create a resource group

resource group is a logical container into which Azure resources like web apps, databases, and storage accounts are deployed and managed.

Next to Resource Group, select New.

Provide a name for the Resource Group and select OK.

Create a resource group

Create a resource group

Step 5: Create an App Service plan

An App Service plan specifies the location, size, and features of the web server farm that hosts your app.

Next to App Service Plan, select New.

In the Configure App Service Plan dialog, update the details as per the requirements and Select

Create and configure an App Service Plan

Create and configure an App Service Plan

Step 6: Create and publish the web app

In Web App Name, type a unique app name or accept the automatically generated unique name. The URL of the web app is http://<app_name>.azurewebsites.net, where <app_name> is your web app name.

Select Create to start creating the Azure resources.

Create Azure resources

Create Azure resources

Now the application is being deployed to Azure.

Deploying to Azure

Deploying to Azure

Once the deployment completes, it publishes the ASP.NET web application to Azure, and then launches the app in the default browser.

Please make use of the below sample to download Excel document in Azure platform.

Sample link:


Take a moment to peruse the documentation where you can find basic Excel document processing options along with the features like import and export data, chart, formulas, conditional formatting, data validation, tables, pivot tables and protect the Excel documents, and most importantly, the PDF, CSV and Image conversions with code examples.

Note:

A new version of Essential Studio&reg; for ASP.NET is available. Versions prior to the release of Essential Studio&reg; 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential Studio for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.

The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential Studio&reg; for ASP.NET. Although Syncfusion&reg; will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.

If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion components.

If you have any queries or require clarification, please let us know in the comments below or contact us through our support forumsSupport Tickets, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied