Create XLS, XLSX, XLSB, ODS, CSV or HTML files from your C# / VB.NET applications

The following example shows how you can create Excel (XLS, XLSX, XLSB, ODS, CSV) or HTML files by using only the GemBox.Spreadsheet .NET component.

GemBox.Spreadsheet uses the same model for all file formats. With our component you can define your spreadsheet, specify an output file format, and GemBox.Spreadsheet will handle writing the spreadsheet to the file format.

Gembox.Spreadsheet can save your model to a file on a disk, or to a stream which can be then added to your database or sent to a client's web browser. You can also use advanced features like encryption or specify options specific to some file formats.

Steps for creating files

You can create a new file with just a few lines of code. You only need an IDE like Visual Studio or JetBrains Rider and .NET Framework, .NET Core, or any other platform that implements .NET Standard.

Follow these steps to define the file's content and save it to a file format of your choice:

  • Create or use an existing C# or VB.NET project.
  • Download and install GemBox.Spreadsheet Setup.
  • Add a reference to GemBox.Spreadsheet.dll within your C# or VB.NET project.
  • Optionally, you can add GemBox.Spreadsheet Nuget package to your C# or VB.NET project.
  • Execute the C#/VB.NET code below.

Try creating files online

You can test creating basic files with the interactive example below. Just choose the output file format, click Run Example, and download the generated file.

The following example creates an Excel file with one worksheet, inserts text "Hello world!" into cell "A1", and saves the file to a file format. After clicking on Run example, the C#/VB.NET code will be compiled, and the model will be saved to your chosen file format with only .NET framework and the GemBox.Spreadsheet component.

using GemBox.Spreadsheet;

class Program
{
    static void Main()
    {
        // If you are using the Professional version, enter your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        // Create Excel file.
        var workbook = new ExcelFile();

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

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

        // Save the Excel file to a file format of your choice.
        workbook.Save("Create.%OutputFileType%");
    }
}
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

        ' If you are using the Professional version, enter your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        ' Create Excel file.
        Dim workbook = New ExcelFile()

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

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

        ' Save the Excel file to a file format of your choice.
        workbook.Save("Create.%OutputFileType%")
    End Sub
End Module

Supported output file formats

XLSX, ODS and HTML created with GemBox.Spreadsheet
Screenshot of XLSX, ODS and HTML created with GemBox.Spreadsheet

GemBox.Spreadsheet supports creating the following files: XLSX, XLS, XLSB, ODS, CSV, TXT, XLSM, XLTX, XLTM, HTML, MHTML, PDF, XPS, PNG, JPEG, GIF, BMP, TIFF, WMP, SVG.

Files can be saved on a disk, or saved to a stream which can then be saved to your database or sent to a client's web browser.

You can additionally use an overload that accepts options specific to a file format, like a delimiter for CSV files or if images should be embedded directly into an HTML file.

To see how to add content, charts, images, and specify other features, click on "All examples" and search for the features you need. In most cases, instead of creating a file from scratch, it is easier to create a template Excel file and just fill the required values. Check the Template use example to see how it works.

Additional features

To see how to add basic content, you can start from the following examples:

Since GemBox.Spreadsheet is completely written in C# and uses caching techniques, it offers both speed and memory optimizations. With GemBox.Spreadsheet you can read and write 1,000,000 rows with less than 256MB RAM and less than 4 seconds. You can test the performance yourself with the Performance example.

See also


Next steps

GemBox.Spreadsheet is a .NET component that enables you to read, write, edit, convert, and print spreadsheet files from your .NET applications using one simple API.

Download Buy