USING IRONXL

Create a CSV file using C#

Jordi Bardia
Jordi Bardia
October 7, 2020
Updated December 21, 2023
Share:

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


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
Install-Package IronXL.Excel

Create a CSV file using C#, Figure 1: IronXL.Excel NuGet Package 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, and then simply saves it in the CSV format by using the SaveAsCsv method.

The Normal Excel workbook contains the following data:

Create a CSV file using C#, Figure 2: Excel data to be converted to CSV


/**
Save as CSV file
anchor-save-workbook-as-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
/**
Save as CSV file
anchor-save-workbook-as-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
'''
'''Save as CSV file
'''anchor-save-workbook-as-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
$vbLabelText   $csharpLabel

Additionally, the IronXL Excel library provides the following features:

  • A broad set of functions, including data manipulation, data export, data import and importing from other sources.
  • Support chart management that is fully compatible with Excel.
  • Support for Excel's most popular file formats (.xlsx) and other file formats.
  • Support for cell formatting such as text alignment, font size, color, etc.
  • Ability to control the way that cells are displayed in an Excel workbook (e.g. gridlines).

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
Documentation related to Library Quick Access
Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he says it’s one of his favorite aspects of working with Iron Software. Jordi grew up in Miami, Florida and studied Computer Science and Statistics at University of Florida.
< PREVIOUS
How to Merge Cells in Excel: Step by Step Tutorial
NEXT >
Generate Excel Files in C#