CSV to Excel Conversion

27 Jul 20264 minutes to read

XlsIO can read a CSV file with IWorkbooks.Open and write the result to an Excel workbook with IWorkbook.SaveAs. The default delimiter when opening a CSV is a comma (,). To read other delimited formats, pass the matching character to the Open overload.

NOTE

IMPORTANT: Before running the samples on this page, install the required NuGet package for your target platform and register your Syncfusion license key. For more information, see the Licensing overview.

The supported delimiters are:

  • Comma (,) — the default.
  • Tab (\t) — used to open a TSV file.
  • Semicolon (;)
  • Colon (:)
  • Space ( )
  • Equals (=)

The following code example illustrates how to convert a CSV to an Excel file.

using (ExcelEngine excelEngine = new ExcelEngine())
{
	IApplication application = excelEngine.Excel;
	application.DefaultVersion = ExcelVersion.Xlsx;

	//Open the CSV file
	IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.csv"), ",");
	IWorksheet worksheet = workbook.Worksheets[0];

	//Saving the workbook 
	workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
  IApplication application = excelEngine.Excel;
  application.DefaultVersion = ExcelVersion.Xlsx;

  //Open the CSV file
  IWorkbook workbook = application.Workbooks.Open("InputTemplate.csv", ",");

  //Saving the workbook 
  workbook.SaveAs("Output.xlsx");
}
Using excelEngine As New ExcelEngine()
  Dim application As IApplication = excelEngine.Excel
  application.DefaultVersion = ExcelVersion.Xlsx

  ' Open the CSV file
  Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.csv", ",")

  ' Saving the workbook
  workbook.SaveAs("Output.xlsx")
End Using

A complete working example to convert CSV to an Excel file in C# is present on this GitHub page.

TSV to Excel Conversion

TSV (Tab-Separated Values) files are loaded by passing the tab character (\t in C#, vbTab in VB.NET) as the delimiter to Workbooks.Open. The workbook is then written to .xlsx with SaveAs.

The following code example illustrates how to convert a TSV to an Excel file.

using (ExcelEngine excelEngine = new ExcelEngine())
{
	IApplication application = excelEngine.Excel;
	application.DefaultVersion = ExcelVersion.Xlsx;

	//Open the TSV file
	IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.tsv"), "\t");

	//Save the workbook
	workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
  IApplication application = excelEngine.Excel;
  application.DefaultVersion = ExcelVersion.Xlsx;

  //Open the TSV file
  IWorkbook workbook = application.Workbooks.Open("InputTemplate.tsv", "\t");

  //Saving the workbook 
  workbook.SaveAs("Output.xlsx");
}
Using excelEngine As New ExcelEngine()
  Dim application As IApplication = excelEngine.Excel
  application.DefaultVersion = ExcelVersion.Xlsx

  ' Open the TSV file
  Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.tsv", vbTab)

  ' Saving the workbook
  workbook.SaveAs("Output.xlsx")
End Using

A complete working example to convert TSV to an Excel file in C# is present on this GitHub page.

See also