Create a CSV file using C#
Create and output a CSV file easily with IronXL's free for development. The following code shows you how.
How to Create a CSV file using C#
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 IronXL via the NuGet Package Manager Console
Install-Package IronXL.Excel
# Install IronXL via the NuGet Package Manager Console
Install-Package IronXL.Excel
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:
// Import the IronXL library
using IronXL;
class Program
{
static void Main()
{
// Load an existing workbook
WorkBook wb = WorkBook.Load("Normal_Excel_File.xlsx"); // You can import .xls, .csv, or .tsv files
// Save the workbook to a CSV file. This will save the first worksheet as a CSV.
wb.SaveAsCsv("SaveAsCSV.csv", ","); // This will output: SaveAsCSV.Sheet1.csv
}
}
// Import the IronXL library
using IronXL;
class Program
{
static void Main()
{
// Load an existing workbook
WorkBook wb = WorkBook.Load("Normal_Excel_File.xlsx"); // You can import .xls, .csv, or .tsv files
// Save the workbook to a CSV file. This will save the first worksheet as a CSV.
wb.SaveAsCsv("SaveAsCSV.csv", ","); // This will output: SaveAsCSV.Sheet1.csv
}
}
' Import the IronXL library
Imports IronXL
Friend Class Program
Shared Sub Main()
' Load an existing workbook
Dim wb As WorkBook = WorkBook.Load("Normal_Excel_File.xlsx") ' You can import .xls, .csv, or .tsv files
' Save the workbook to a CSV file. This will save the first worksheet as a CSV.
wb.SaveAsCsv("SaveAsCSV.csv", ",") ' This will output: SaveAsCSV.Sheet1.csv
End Sub
End Class
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 for 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 DocumentationFrequently Asked Questions
What is this software library used for manipulating Excel files?
IronXL is a software library for C# that allows developers to manipulate Excel files, including creating and outputting CSV files, among other features.
How do I install the package for manipulating Excel files?
You can install IronXL via the NuGet Package Manager by right-clicking on the Solution in the Solution Explorer, selecting 'Manage NuGet Packages', browsing for IronXL.Excel, and clicking 'Install'. Alternatively, use the command `Install-Package IronXL.Excel` in the NuGet Package Manager Console.
How can I create a CSV file using a C# library?
To create a CSV file, load an existing Excel workbook using IronXL and then use the `SaveAsCsv` method to save it in the CSV format.
What file formats does the Excel manipulation library support?
IronXL supports Excel's most popular file formats, including .xlsx, as well as other formats like .xls, .csv, and .tsv.
Can I manipulate data in Excel files using a C# library?
Yes, IronXL offers a broad set of functions for data manipulation, including data import, data export, and importing from other sources.
Does the C# Excel library support chart management?
Yes, IronXL fully supports chart management that is compatible with Excel.
What cell formatting options does the Excel library provide?
IronXL supports various cell formatting options such as text alignment, font size, color, and gridlines.
Where can I find the API reference documentation for the Excel library?
The IronXL API reference documentation can be accessed on the IronXL website under the API Reference Documentation section.