GemBox Software - .NET Components for Reading/Writing Excel files and Compound Document files  
Search gemboxsoftware.com:    
    
 
 
 
 
  FAQ
  Bugs & Features
  Articles



How to Save to Excel or HTML files from your .NET applications?

Following example shows how to save to 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 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 creates Excel file (in XLS format) with one worksheet, inserts text "Hello world!" into cell "A1" and saves the file to disc:

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 save the file to another format you only need to replace the SaveXls method with preferred one (SaveXlsx, SaveCsv or SaveHtml).

















© GemBox Software. All rights reserved.