Create simple spreadsheet in C#, VB.NET using XlsIO
Syncfusion® Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. It also converts Excel documents to PDF files. Using this library, you can create a simple spreadsheet in C# or VB.NET.
XlsIO has a very intuitive object model, similar to the Excel object model. Therefore, the process of creating a new spreadsheet is similar to what you would do using Microsoft Excel.
Steps to create a simple spreadsheet using XlsIO, programmatically:
Step 1: Create a new C# console application project.
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
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 a 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 a 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 a 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
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?
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.
For current customers, you can check out our components from the [License and Downloads](https://www.syncfusion.com/sales/teamlicense) page. If you are new to Syncfusion, you can try our 30-day [free trial](https://www.syncfusion.com/downloads/blazor) to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our [support forums](https://www.syncfusion.com/forums), [Direct-Trac](https://support.syncfusion.com/support/tickets/create), or [feedback portal](https://www.syncfusion.com/feedback/blazor-components?control=diagram). We are always happy to assist