Published September 16, 2022
How to Use a CSV Parser in C#
It's simple to create a CSV parser. With only two lines of code you can load a CSV document, convert and export it to Excel.
- [c# csv parser] Please help check correct of this article if code example is correct. Article is old
- How to use CSV Parser in C#
How to use CSV Parser in C#
- Install C# library parse CSV file
- Use
Load
method to parse various file formats including CSV - Inspect and modify the data in C#
- Export the data into a new CSV file
- Each Excel sheet will be exported into separate CSV file
Create CSV Parser for .NET
Step 1
1. Download IronXL
Before I show you how to create a CSV parser, we'll first install IronXL to your project (free in development and debugging environment).
You can download directly from the Iron Software website by using the following link: https://ironsoftware.com/csharp/excel/docs/
or
- In Visual Studio select the Project menu
- Click Manage NuGet Packages
- Search for IronXL.Excel
- Click Install
Simply, you can also use the Developer Command Prompt:
PM> Install-Package IronXL.Excel
How to Tutorial
2. Create a New Project
After you have installed IronXL, create a new project and add the IronXL namespace
using IronXL;
using IronXL;
Imports IronXL
3. Load a Excel into CSV File
The following code uses the Workbook object’s Load
method to load a CSV file into Excel. This file is then parsed. Lastly, it uses the SaveAs
method to save the file in the csv format.
private void button4_Click(object sender, EventArgs e)
{
// Import XLSX, XLS, XLSM, XLTX, CSV and TSV
WorkBook workBook = WorkBook.Load("Normal_Excel_File.xlsx");
//Exported as : Parsed_CSV.Sheet1.csv
workBook.SaveAs("Parsed_CSV.csv");
}
private void button4_Click(object sender, EventArgs e)
{
// Import XLSX, XLS, XLSM, XLTX, CSV and TSV
WorkBook workBook = WorkBook.Load("Normal_Excel_File.xlsx");
//Exported as : Parsed_CSV.Sheet1.csv
workBook.SaveAs("Parsed_CSV.csv");
}
Private Sub button4_Click(ByVal sender As Object, ByVal e As EventArgs)
' Import XLSX, XLS, XLSM, XLTX, CSV and TSV
Dim workBook As WorkBook = WorkBook.Load("Normal_Excel_File.xlsx")
'Exported as : Parsed_CSV.Sheet1.csv
workBook.SaveAs("Parsed_CSV.csv")
End Sub
Don’t forget to create an Excel Workbook named Normal_Excel_File.xlsx containing the following data:
4. Export the Parsed CSV
Interestingly, the exported CSV file will be saved as Parsed_CSV.Sheet1.csv because the data is on Sheet1 inside of the Excel Workbook. Below is what the file would look like in File Explorer when selected.
You can download the software product from this link.
Library Quick Access
IronXL API Reference Documentation
Learn more and share how to merge, unmerge, and work with cells in Excel spreadsheets using the handy IronXL API Reference Documentation.
IronXL API Reference Documentation