Following example shows how to generate Excel or HTML files by using only GemBox.Spreadsheet .NET component.
GemBox.Spreadsheet is a .NET component which provides easy and high performance way to write, read or convert native Microsoft Excel files (XLS, CSV, ODS or XLSX) and HTML files without the need for Microsoft Excel on either the developer or client machines. GemBox.Spreadsheet Free comes free of charge while GemBox.Spreadsheet Professional is a commercial version (licensed per developer). Find more information about GemBox.Spreadsheet features or reasons why our component is better than Excel Automation.
Example generates Excel file (in XLS format) with one worksheet and inserts text “Hello world!” into cell “A1″:
C# code:
ExcelFile ef = new ExcelFile(); // Adds new worksheet to excelFile. ExcelWorksheet ws = ef.Worksheets.Add("New worksheet"); // Sets the value of the cell "A1". ws.Cells["A1"].Value = "Hello world!"; // Saves the excel file. ef.SaveXls("excelFile.xls");
Visual Basic .NET code:
Dim ef As New ExcelFile ' Adds new worksheet to excelFile. Dim ws As ExcelWorksheet = ef.Worksheets.Add("New worksheet") ' Sets the value of the cell "A1". ws.Cells("A1").Value = "Hello world!" ' Saves the excel file. ef.SaveXls("excelFile.xls")
To generate the file in another format you only need to replace the SaveXls method with preferred one (SaveXlsx, SaveOds, SaveCsv or SaveHtml).
