How to Read and Write to Excel Spreadsheet from your C#, VB.NET or ASP.NET applications? Following example shows how to read or write to Excel Spreadsheet 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 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 then Excel Automation.
Example reads Excel file (in XLS format), selects the first spreadsheet, changes the value of the cell "A1" and writes the new file:
|
ExcelFile ef = new ExcelFile();
// Loads Excel file.
ef.LoadXls("filename.xls");
// Selects first worksheet.
ExcelWorksheet ws = ef.Worksheets[0];
// Change the value of the cell "A1".
ws.Cells["A1"].Value = "Hello world!";
// Saves the file in XLS format.
ef.SaveXls("NewFile.xls");
|
|
Dim ef As New ExcelFile
' Loads Excel file.
ef.LoadXls("filename.xls")
' Selects first worksheet.
Dim ws As
ExcelWorksheet = ef.Worksheets(0)
' Change the value of the cell "A1".
ws.Cells("A1").Value = "Hello world!"
' Saves the file in XLS format.
ef.SaveXls("NewFile.xls")
|
To read/write the file to another format you only need to replace the LoadXls/SaveXls method with preferred one (LoadXlsx/SaveXlsx, LoadCsv/SaveCsv or SaveHtml).
|