The Syncfusion .NET Excel Library (XlsIO) offers comprehensive support for converting CSV files to Excel format. It allows users to create Excel documents from CSV files, supporting various CSV formats. Formats such as CSV, TXT, and other delimited files can be converted into Excel formats like .xlsx, .xls, .xlsm, and .xltm.
Here is an example of how to save a CSV file as an Excel document using C#.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
using (FileStream inputStream = new FileStream("sample.csv",FileMode.Open, FileAccess.Read))
{
//Opening CSV document with comma separator.
IWorkbook workbook = application.Workbooks.Open(inputStream, ",");
using (FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite))
{
//Save the CSV data as Excel.
workbook.SaveAs(outputStream);
}
}
}
Here is an example of how to convert a TSV file to Excel in C#.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
using (FileStream inputStream = new FileStream("sample.tsv", FileMode.Open, FileAccess.Read))
{
IWorkbook workbook = application.Workbooks.Open(inputStream, "\t");
using (FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite))
{
// Save the workbook in Excel format.
workbook.SaveAs(outputStream);
}
}
}
Developers can also use the Syncfusion .NET Excel Library to perform the following conversions:
Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion is proud to hold the following industry awards.