Articles in this section
Category / Section

Create simple spreadsheet in C#, VB.NET using XlsIO

4 mins read

Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. Also, converts Excel documents to PDF files. Using this library, you can create simple spreadsheet in C#, VB.NET.

XlsIO has a very intuitive object model like Excel object model. So, the process of creating a new spreadsheet is like what you would do using Microsoft Excel.

Steps to create simple spreadsheet using XlsIO, programmatically:

Step 1: Create a new C# console application project.

Create a new C# console application

Create a new C# console application

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

Install NUGET package

Install NuGet package

Step 3: Include the following namespace in the Program.cs file.

C#

using Syncfusion.XlsIO;

 

VB.NET

Imports Syncfusion.XlsIO

 

Step 4: Create a new instance of XlsIO. This is equivalent to launching Microsoft Excel, but the difference is that Microsoft Excel will create spreadsheet by default but in XlsIO, we must create spreadsheet after launching an Excel application. At this point we have a workbook object that is like the blank workbook in Microsoft Excel. We can create any number of new workbooks that we want. XlsIO has many APIs that allow you to manipulate the contents and formatting of the spreadsheet just like you would do in Microsoft Excel UI. Use the following code snippet to create simple spreadsheet using XlsIO in C#, VB.NET.

C#

//Create Excel engine
using (ExcelEngine excelEngine = new ExcelEngine())
{
    //Instantiate the application object
    IApplication application = excelEngine.Excel;
 
    //Create spreadsheet or workbook object
    IWorkbook workbook = application.Workbooks.Create(1);
 
    //The first worksheet object in the worksheets collection is accessed
    IWorksheet worksheet = workbook.Worksheets[0];
 
    //A text is set in the first cell of the worksheet
    worksheet[1, 1].Text = "Hello World!";
 
    //Save the spreadsheet
    workbook.SaveAs("Output.xlsx");
}

 

VB.NET

'Create Excel engine
Using excelEngine As ExcelEngine = New ExcelEngine()
    'Instantiate the application object
    Dim application As IApplication = excelEngine.Excel
 
    'Create spreadsheet or workbook object
    Dim workbook As IWorkbook = application.Workbooks.Create(1)
 
    'The first worksheet object in the worksheets collection is accessed
    Dim worksheet As IWorksheet = workbook.Worksheets(0)
 
    'A text is set in the first cell of the worksheet
    worksheet(1, 1).Text = "Hello World!"
 
    'Save the spreadsheet
    workbook.SaveAs("Output.xlsx")
End Using

 

A complete Windows Forms working example of how to create simple spreadsheet using XlsIO in C# and VB.NET can be downloaded from Create Simple Spreadsheet.zip.

By executing the program, you will get the output Excel file as shown below.

Output excel document

Output Excel document

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

See Also:

How do I create a spreadsheet based on an existing template?

Does the XlsIO component support Excel spreadsheets that have VBA code in them?

 How to create an Excel file in Windows Forms

How do I protect certain cells in a spreadsheet?

How do I create a workbook with the specified number of worksheets?

Note:

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.

 

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