GemBox Introduction


GemBox offers fast and easy–to–use .NET and Java components for developers, with a strong focus on file formats and well–documented APIs. Do you need to easily add the ability to read and write from various file formats from within you Java or .NET program? GemBox has the following modules: Spreadsheet, Document, PDF, Email, Presentation, Spreadsheet for Java and finally the Bundle. Bundle is a package of .NET components that enable you to process office files (spreadsheets, documents, presentations, and emails).

Excel

In this post I will have a look at the Spreadsheet feature. Examples are the fastest way to get started with GemBox.Spreadsheet. To see the examples go to: https://www.gemboxsoftware.com/spreadsheet/examples. Use a single programming interface for multiple file formats (XLSX, XLS, ODS, CSV, HTML, PDF, and XPS). Read, write, view, and edit spreadsheets in .NET Framework, .NET Core, Mono and Xamarin. Edit sheets, cells, styles and formatting, formulas, images, charts, pivot tables, protection and so on.

Free Version

GemBox.Spreadsheet Free delivers the same performance and set of features as the Professional version. However, the following limitations are imposed during reading or writing files:

  • Maximum number of rows per sheet is 150.
  • Maximum number of sheets per workbook is 5.

Using the GemBox.Spreadsheet component is easy and straightforward. After referencing GemBox.Spreadsheet.dll from your project, you can use the following code snippet to generate a simple Excel file:

static void Main()
{
    // Set license key to use GemBox.Spreadsheet in Free mode.
    SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

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

    // Create a new worksheet and set cell A1 value to 'Hello world!'.
    workbook.Worksheets.Add("Sheet 1").Cells["A1"].Value = "Hello world!";

    // Save to XLSX file.
    workbook.Save("Spreadsheet.xlsx");
}

I tested it in Visual Studio using a .NET Core 2.0 project and it worked. It does create an Excel file in the project folder. There is nothing on the interface to tell the user that it did so. We would need to write something to inform the user. Also, the program crashes if the Excel file is open. The program returns an error saying that the process cannot access the file … because it is being used by another process. This makes sense. If the Excel file is closed, the program will simple overwrite the exiting file.

View

I modified some code from the GemBox website and ran this in the ASP.NET Core MVC project. It worked. I was able to easily add a second worksheet and add some content to it.

public IActionResult About()
{
    // If using Professional version, put your serial key below.
    SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

    var workbook = new ExcelFile();
    var worksheet = workbook.Worksheets.Add("Hello World");

    worksheet.Cells[0, 0].Value = "English:";
    worksheet.Cells[0, 1].Value = "Hello";

    worksheet.Cells[1, 0].Value = "Russian:";
    // Using UNICODE string.
    worksheet.Cells[1, 1].Value = new string(new char[] { '\u0417', '\u0434', '\u0440', '\u0430', '\u0432', '\u0441', '\u0442', '\u0432', '\u0443', '\u0439', '\u0442', '\u0435' });

    worksheet.Cells[2, 0].Value = "Chinese:";
    // Using UNICODE string.
    worksheet.Cells[2, 1].Value = new string(new char[] { '\u4f60', '\u597d' });

    worksheet.Cells[4, 0].Value = "In order to see Russian and Chinese characters you need to have appropriate fonts on your PC.";
    worksheet.Cells.GetSubrangeAbsolute(4, 0, 4, 7).Merged = true;

    worksheet = workbook.Worksheets.Add("Second Sheet");
    worksheet.Cells[1, 0].Value = "Hello there from cell A2 which is (1, 0) or (row, col)";

    workbook.Save("Hello World.xlsx");
    return View();
}

Free Mode

There are other versions: free versions, trial versions, time limited and professional. You can use all components in the free mode for any purpose, including use in commercial applications. The free mode delivers the same performance and set of features as the professional mode. The only differences are some limitations — for example, a limited number of rows per sheet in a GemBox.Spreadsheet.