title | description | type | page_title | slug | position | tags | res_type |
---|---|---|---|---|---|---|---|
Convert CSV to XLSX |
Learn how to convert CSV file to XLSX using SpreadProcessing. |
how-to |
Convert CSV to XLSX |
convert-csv-to-xlsx |
0 |
csv, xlsx, excel, spreadprocessing |
kb |
Product Version | Product | Author |
---|---|---|
2020.1.310 | RadSpreadProcessing | Dimitar Karamfilov |
The below example shows how you can easily convert a CSV file to XLSX format.
Use the [SpreadProcessing]({%slug radspreadprocessing-overview%}) library to convert the file.
{{region kb-convert-to-xlsx1}} 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);
}
{{endregion}}