Create Excel File in C#, VB.NET

This section is designed to provide developers a simple solution on how to create Excel file in C#, VB.NET via this .NET Excel component Spire.XLS for .NET.

Spire.XLS for .NET allows you to create Excel file on the formats of Excel (.xls) 97-2003 and Excel (.xlsx) 2007 and Excel(.xlsx)2010 without installing MS Excel or any third party library. Apart from creating Excel file, this Excel api also enables you to read, edit and manipulate Excel files with high efficiency in .NET applications.

Below is the sample code for you to find how you can create an Excel file:

using System.Drawing;
using Spire.Xls;

namespace Create_Excel_File
    class Program
        static void Main(string[] args)
            //Initialize a new Workboook object
            Workbook workbook = new Workbook();
            //Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];
            //Write string values in a cell
            sheet.Range["A3"].Text = "This Excel Document is Created by Spire.XLS for .NET";
            //Save workbook to disk
            catch { }
Imports System.Drawing
Imports Spire.Xls

Namespace Create_Excel_File
	Class Program
		Private Shared Sub Main(args As String())
			'Initialize a new Workboook object
			Dim workbook As New Workbook()
			'Get the first worksheet
			Dim sheet As Worksheet = workbook.Worksheets(0)
			'Write string values in a cell
			sheet.Range("A3").Text = "This Excel Document is Created by Spire.XLS for .NET"
			'Save workbook to disk
			End Try
		End Sub
	End Class
End Namespace

The Created Excel File

After executing above code, The Excel file is created and some string values are also added in the first Worksheet”Sheet1”. Please see the screenshot below:

Create Excel File