How to create a CSV file using C#

Create and output a CSV file easily with IronXL's free for development software. The following code shows you how.

Code Examples

Save as CSV file
using IronXL;
WorkBook wb = WorkBook.Load("Normal_Excel_File.xlsx"); //Import .xls, .csv, or .tsv file
wb.SaveAsCsv("SaveAsCSV.csv", ","); //Saved as : SaveAsCSV.Sheet1.csv
Imports IronXL
Private wb As WorkBook = WorkBook.Load("Normal_Excel_File.xlsx") 'Import .xls, .csv, or .tsv file
wb.SaveAsCsv("SaveAsCSV.csv", ",") 'Saved as : SaveAsCSV.Sheet1.csv
Jump to Article
Try IronXL free for development


Step 1

1. Add IronXL Package

First, you must have IronXL installed. There are various options. You can download it directly: https://ironsoftware.com/csharp/excel/docs/

Or you can import the IronXL NuGet package by following the next few steps

  • Right click on the Solution in the Solution Explorer
  • Click Manage NuGet Packages
  • Browse for IronXL.Excel
  • Click Install
PM> Install-Package IronPdf
IronXL.Excel NuGet Package
Figure 1 - IronXL.Excel NuGet Package


How to Tutorial

2. Save Workbook as CSV

Easy as that!

Here is the code for this little project. This code loads an existing Excel workbook, then simply saves it in the CSV format by using the SaveAsCsv method.

The Normal Excel workbook contains the following data:

Excel data to be converted to CSV
Figure 2 - Excel data to be converted to CSV
using IronXL;
WorkBook wb = WorkBook.Load("Normal_Excel_File.xlsx"); //Import .xls, .csv, or .tsv file
wb.SaveAsCsv("SaveAsCSV.csv", ","); //Saved as : SaveAsCSV.Sheet1.csv
using IronXL;
WorkBook wb = WorkBook.Load("Normal_Excel_File.xlsx"); //Import .xls, .csv, or .tsv file
wb.SaveAsCsv("SaveAsCSV.csv", ","); //Saved as : SaveAsCSV.Sheet1.csv
Imports IronXL
Private wb As WorkBook = WorkBook.Load("Normal_Excel_File.xlsx") 'Import .xls, .csv, or .tsv file
wb.SaveAsCsv("SaveAsCSV.csv", ",") 'Saved as : SaveAsCSV.Sheet1.csv
VB   C#


Library Quick Access

IronXL Object Reference Documentation

Learn more and share how to merge, unmerge, and work with cells in Excel spreadsheets using the handy IronXL Object Reference Documentation.

IronXL Object Reference Documentation