How to write a Report in Excel or HTML files from your .NET applications?

Following example shows how to write a report in Excel or HTML files by using only GemBox.Spreadsheet .NET component.

GemBox.Spreadsheet is a C# / VB.NET component which 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.

Example reads template Excel file (in XLS format), fills it with report data and writes the new file:

C# code:

// Load the template file.
var workbook = ExcelFile.Load("InvoiceTemplate.xls");

// Select the first worksheet.
var worksheet = workbook.Worksheets[0];

// Fill the data.
worksheet.Cells["J5"].Value = 14;
worksheet.Cells["J6"].Value = new DateTime(2008, 4, 20);
worksheet.Cells["J6"].Style.NumberFormat = "m/dd/yyyy";

worksheet.Cells["D12"].Value = "ACME Corp";
worksheet.Cells["D13"].Value = "240 Old Country Road, Springfield, IL";
worksheet.Cells["D14"].Value = "USA";
worksheet.Cells["D15"].Value = "Joe Smith";

worksheet.Cells["E18"].Value = "6-APR-08 until 7-APR-08.";

worksheet.Cells[21, 1].Value = new DateTime(2008, 4, 6);
worksheet.Cells[21, 1].Style.NumberFormat = "dddd, mmmm dd, yyyy";
worksheet.Cells[21, 4].Value = 8;

worksheet.Cells["B36"].Value = "Payment via check.";

// Save the file.

Visual Basic .NET code:

' Load the template file.
Dim workbook = ExcelFile.Load("InvoiceTemplate.xls")

' Select the first worksheet.
Dim worksheet = workbook.Worksheets(0)

' Fill the data.
worksheet.Cells("J5").Value = 14
worksheet.Cells("J6").Value = New DateTime(2008, 4, 20)
worksheet.Cells("J6").Style.NumberFormat = "m/dd/yyyy"

worksheet.Cells("D12").Value = "ACME Corp"
worksheet.Cells("D13").Value = "240 Old Country Road, Springfield, IL"
worksheet.Cells("D14").Value = "USA"
worksheet.Cells("D15").Value = "Joe Smith"

worksheet.Cells("E18").Value = "6-APR-08 until 7-APR-08."

worksheet.Cells(21, 1).Value = New DateTime(2008, 4, 6)
worksheet.Cells(21, 1).Style.NumberFormat = "dddd, mmmm dd, yyyy"
worksheet.Cells(21, 4).Value = 8

worksheet.Cells("B36").Value = "Payment via check."

' Save the file.

Template file had no report data and looked like this:

New file was created by using the code above and looks like this: