We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Create Excel file in ASP.NET Web Forms

Platform: ASP.NET Web Forms |
Control: XlsIO

Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. Also, converts Excel documents to PDF files.

This sample explains the creation of an Excel file with simple text, in ASP.NET Web Forms platform.

Steps to create an Excel file in ASP.NET Web Forms:

Step 1: Create a new C# ASP.NET Web Application project.

Create a new C# ASP.NET Web application project in  .NET Excel library

Create a new C# ASP.NET Web application project

Step 2: Select the Web Forms template.

Select the project template as Web Forms in  .NET Excel library

Select the project template as Web Forms

Step 3: Install the Syncfusion.XlsIO.AspNet NuGet package as reference to your .NET Framework application from NuGet.org.

Install NuGet package to the project in  .NET Excel library

Install NuGet package to the project

Step 3: Add a new Web Form in the web application project.

  1. To add the new Web Form, right click on the project and select Add->New Item.
  2. Select the Web Form and name it as MainPage. Step 4: Include the following code snippet in MainPage.aspx to add a new button.

HTML

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainPage.aspx.cs" Inherits="CreateExcel.MainPage" %>
 
<!DOCTYPE html>
 
<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 Excel" OnClick="OnButtonClicked" />
        </div>
    </form>
</body>
</html>

 

Step 5: Include the following namespaces in MainPage.aspx.cs file.

C#

using Syncfusion.XlsIO;
using System;

 

VB.NET

Imports Syncfusion.XlsIO
Imports System

 

Step 6: Have a click event for the button in MainPage.aspx.cs file.

C#

protected void OnButtonClicked(object sender, EventArgs args)
{
 
}

 

VB.NET

Protected Sub OnButtonClicked(ByVal sender As Object, ByVal args As EventArgs)
 
End Sub

 

Step 7: Include the following code snippet in click event of the button, to create an Excel file.

C#

//Create an instance of ExcelEngine
using (ExcelEngine excelEngine = new ExcelEngine())
{
    //Instantiate the Excel application object
    IApplication application = excelEngine.Excel;
 
    //Set the default application version as Excel 2016
    application.DefaultVersion = ExcelVersion.Excel2016;
 
    //Create a workbook with a worksheet
    IWorkbook workbook = application.Workbooks.Create(1);
 
    //Access 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()
    'Instantiate the Excel application object
    Dim application As IApplication = excelEngine.Excel
 
    'Set the default application version as Excel 2016
    application.DefaultVersion = ExcelVersion.Excel2016
 
    'Create a new Excel workbook
    Dim workbook As IWorkbook = application.Workbooks.Create(1)
 
    'Get the first worksheet in the workbook into IWorksheet
    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", Response, ExcelDownloadType.Open, ExcelHttpContentType.Excel2016)
End Using

 

A complete working sample to create an Excel file in ASP.NET Web Forms application using Syncfusion Excel (XlsIO) library can be downloaded from CreateExcel.zip.

By executing the program, you will get the output Excel document as follows.

Create Excel in ASP.NET WebForms in  .NET Excel library

Output Excel document

Take a moment to peruse the documentation, where you can find basic worksheet data manipulation options along with features like Conditional Formatting, worksheet calculations through Formulas, adding Charts in worksheet or workbook, organizing and analyzing data through Tables and Pivot Tables, appending multiple records to worksheet using Template Markers, and most importantly PDF and Image conversions etc. with code examples.

See Also:

Create Excel file in Windows Forms

Create Excel file in WPF

Create Excel file in ASP.NET MVC

Create Excel file in ASP.NET Core

Create Excel file in UWP

Create Excel file in Xamarin

Click here to explore the rich set of Syncfusion Excel (XlsIO) library features.

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer the link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

 

 

 

2X faster development

The ultimate ASP.NET Web Forms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile