How to open tab-delimited CSV files in .NET Excel Library
16 Aug 20262 minutes to read
Syncfusion XlsIO allows you to open CSV files with custom delimiters, including tab delimiters. When opening a CSV file, you can specify the delimiter character as the second parameter in the Open method.
The following code example illustrates how to open a CSV file with a tab delimiter using XlsIO.
using (ExcelEngine excelEngine = new ExcelEngine())
{
// Instantiate the Excel application object
IApplication application = excelEngine.Excel;
// Assign default application version
application.DefaultVersion = ExcelVersion.Xlsx;
// Open a CSV file with a tab delimiter ("\t")
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.csv"), "\t");
// Access the first worksheet from the workbook
IWorksheet worksheet = workbook.Worksheets[0];
// Save the workbook to disk in XLSX format
workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx"));
}using (ExcelEngine excelEngine = new ExcelEngine())
{
// Instantiate the Excel application object
IApplication application = excelEngine.Excel;
// Assign default application version
application.DefaultVersion = ExcelVersion.Xlsx;
// Open a CSV file with a tab delimiter ("\t")
IWorkbook workbook = application.Workbooks.Open("InputTemplate.csv", "\t");
// Access the first worksheet from the workbook
IWorksheet worksheet = workbook.Worksheets[0];
// Save the workbook to disk in XLSX format
workbook.SaveAs("Output.xlsx");
}Using excelEngine As New ExcelEngine()
' Instantiate the Excel application object
Dim application As IApplication = excelEngine.Excel
' Assign default application version
application.DefaultVersion = ExcelVersion.Xlsx
' Open a CSV file with a tab delimiter ("\t")
Dim workbook As IWorkbook = application.Workbooks.Open("nputTemplate.csv", "\t")
' Access the first worksheet from the workbook
Dim worksheet As IWorksheet = workbook.Worksheets(0)
' Save the workbook to disk in XLSX format
workbook.SaveAs("Output.xlsx")
End UsingA complete working example in C# is present on this GitHub page.