Convert CSV to XLSX
Product Version | Product | Author |
---|---|---|
2020.1.310 | RadSpreadProcessing | Dimitar Karamfilov |
Description
The below example shows how you can easily convert a CSV file to XLSX format.
Solution
Use the SpreadProcessing library to convert the file.
Convert CSV to XLSX
static void Main(string[] args)
{
string fileName = @"..\..\FileName.csv";
if (!File.Exists(fileName))
{
throw new FileNotFoundException(String.Format("File {0} was not found!", fileName));
}
Workbook workbook;
var csvFormatProvider = new CsvFormatProvider();
using (Stream input = new FileStream(fileName, FileMode.Open))
{
workbook = csvFormatProvider.Import(input);
}
string resultFile = @"..\..\ResultFile.xlsx";
var formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
using (Stream output = new FileStream(resultFile, FileMode.Create))
{
formatProvider.Export(workbook, output);
}
System.Diagnostics.Process.Start(resultFile);
}