How to Create Excel or HTML files from your C# / VB.NET applications?

The following example shows how to create Excel or HTML files by using only GemBox.Spreadsheet .NET component.

GemBox.Spreadsheet is a C# / VB.NET component that provides simple and efficient way to read, write, convert and print native Microsoft Excel (XLSX, XLS) and other spreadsheet (ODS, CSV) formats and various document formats (HTML, PDF, XPS) from .NET applications without the need for Microsoft Excel on either the developer or client machines.

GemBox.Spreadsheet Free is free of charge while GemBox.Spreadsheet Professional is a commercial version licensed per developer.

For more information, see GemBox.Spreadsheet features and why GemBox.Spreadsheet outperforms Excel automation.

The example below creates an Excel file (in XLS format) with one worksheet and inserts text “Hello world!” into cell “A1”:

C# code:

var workbook = new ExcelFile();

// Add new worksheet to Excel file.
var worksheet = workbook.Worksheets.Add("New worksheet");

// Set the value of the cell "A1".
worksheet.Cells["A1"].Value = "Hello world!";

// Save Excel file.
workbook.Save("Workbook.xls");

Visual Basic .NET code:

Dim workbook = New ExcelFile()

' Add new worksheet to Excel file.
Dim worksheet = workbook.Worksheets.Add("New worksheet")

' Set the value of the cell "A1".
worksheet.Cells("A1").Value = "Hello world!"

' Save Excel file.
workbook.Save("Workbook.xls")