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

The following example shows how you can create Excel (XLS, XLSX, 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 and .NET Framework, .NET Core, or .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, ODS, CSV, TXT, XLSM, XLTX, XLTM, HTML, MHTML, PDF, XPS, PNG, JPEG, GIF, BMP, TIFF, WMP.

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.

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.