Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active August 18, 2021 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/53e4d00e8195ad3eb4ba03fffc4e9315 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/53e4d00e8195ad3eb4ba03fffc4e9315 to your computer and use it in GitHub Desktop.
Convert Excel Spreadsheets to CSV and CSV to XLS/XLSX using C#
// Convert CSV files to XLS/XLSX format in C#
string inputFile = @"path/comma-sparated-values.csv";
string outputFile = @"path/spreadsheet.xlsx";
Contracts.Func<LoadOptions> getLoadOptions = () => new CsvLoadOptions
{
Separator = ','
};
using (Converter converter = new Converter(inputFile))
{
SpreadsheetConvertOptions options = new SpreadsheetConvertOptions();
converter.Convert(outputFile, options);
}
// Convert Excel Spreadsheets to Comma Separated Values CSV format in C#
string inputFile = @"path/spreadsheet.xlsx";
string outputFile = @"path/comma-sparated-values.csv";
using (Converter converter = new Converter(inputFile))
{
SpreadsheetConvertOptions options = new SpreadsheetConvertOptions
{
PageNumber = 2,
PagesCount = 1,
Format = SpreadsheetFileType.Csv // Specify the conversion format
};
converter.Convert(outputFile, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment