How to Convert between XLS, XLSX, CSV and HTML files from your
.NET applications?
Following example shows how to convert between XLS, XLSX, CSV and 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 loads specified input file from specified input format (XLS, XLSX or CSV)
and saves it to specified output file in specified output format (XLS, XLSX, CSV
or HTML):
|
ExcelFile excelFile =
new ExcelFile();
// Load specified file from XLS, XLSX or CSV format.
switch (inputFileFormat)
{
case
"xls":
excelFile.LoadXls(inputFileName);
break;
case
"xlsx":
excelFile.LoadXlsx(inputFileName, XlsxOptions.None);
break;
case
"csv":
excelFile.LoadCsv(inputFileName, CsvType.CommaDelimited);
break;
}
// Save to specified file in XLS, XLSX, CSV or HTML format.
switch (outputFileFormat)
{
case
"xls":
excelFile.SaveXls(outputFileName);
break;
case
"xlsx":
excelFile.SaveXlsx(outputFileName);
break;
case
"csv":
excelFile.SaveCsv(outputFileName, CsvType.CommaDelimited);
break;
case
"html":
excelFile.SaveHtml(outputFileName, null, true);
break;
}
|
|
' Load specified
file from XLS, XLSX or CSV format.
If (inputFileFormat =
"xls") Then
excelFile.LoadXls(inputFileName)
ElseIf (inputFileFormat =
"xlsx") Then
excelFile.LoadXlsx(inputFileName, XlsxOptions.None)
ElseIf (inputFileFormat =
"csv") Then
excelFile.LoadCsv(inputFileName, CsvType.CommaDelimited)
End If
' Save to specified file in XLS, XLSX, CSV or HTML
format.
If (outputFileFormat =
"xls") Then
excelFile.SaveXls(outputFileName)
ElseIf (outputFileFormat =
"xlsx") Then
excelFile.SaveXlsx(outputFileName)
ElseIf (outputFileFormat =
"csv") Then
excelFile.SaveCsv(outputFileName, CsvType.CommaDelimited)
ElseIf (outputFileFormat =
"html") Then
excelFile.SaveHtml(outputFileName,
Nothing, True)
End If
|
|
|
|
© GemBox Software. All rights reserved.
|