How to Convert between XLS, XLSX, ODS, CSV and HTML files from your .NET applications?

Following example shows how to convert between XLS, XLSX, ODS, 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, 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 loads specified input file from specified input format (XLS, XLSX, ODS or CSV) and saves it to specified output file in specified output format (XLS, XLSX, CSV, ODS or HTML):

C# code:

// Load specified file from XLS, XLSX, ODS or CSV format.
switch (inputFileFormat)
{
    case "xls":
        excelFile.LoadXls(inputFileName);
        break;
    case "xlsx":
        excelFile.LoadXlsx(inputFileName, XlsxOptions.None);
        break;
    case "ods":
        excelFile.LoadOds(inputFileName, OdsOptions.None);
        break;
    case "csv":
        excelFile.LoadCsv(inputFileName, CsvType.CommaDelimited);
        break;
}
 
// Save to specified file in XLS, XLSX, ODS, CSV or HTML format.
switch (outputFileFormat)
{
    case "xls":
        excelFile.SaveXls(outputFileName);
        break;
    case "xlsx":
        excelFile.SaveXlsx(outputFileName);
        break;
    case "ods":
        excelFile.SaveOds(outputFileName);
        break;
    case "csv":
        excelFile.SaveCsv(outputFileName, CsvType.CommaDelimited);
        break;
    case "html":
        excelFile.SaveHtml(outputFileName, null, true);
        break;
}

Visual Basic .NET code:

' Load specified file from XLS, XLSX, ODS or CSV format.
If (inputFileFormat = "xls") Then
    excelFile.LoadXls(inputFileName)
ElseIf (inputFileFormat = "xlsx") Then
    excelFile.LoadXlsx(inputFileName, XlsxOptions.None)
ElseIf (inputFileFormat = "ods") Then
    excelFile.LoadOds(inputFileName, OdsOptions.None)
ElseIf (inputFileFormat = "csv") Then
    excelFile.LoadCsv(inputFileName, CsvType.CommaDelimited)
End If
 
' Save to specified file in XLS, XLSX, ODS, CSV or HTML format.
If (outputFileFormat = "xls") Then
    excelFile.SaveXls(outputFileName)
ElseIf (outputFileFormat = "xlsx") Then
    excelFile.SaveXlsx(outputFileName)
ElseIf (outputFileFormat = "ods") Then
    excelFile.SaveOds(outputFileName)
ElseIf (outputFileFormat = "csv") Then
    excelFile.SaveCsv(outputFileName, CsvType.CommaDelimited)
ElseIf (outputFileFormat = "html") Then
    excelFile.SaveHtml(outputFileName, Nothing, True)
End If