Passer au contenu du pied de page
UTILISATION D'IRONXL

Créer un fichier CSV en utilisant 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#

  • Add IronXL Package
  • Load existing WorkBook and save as CSV File
How To Work related to Créer un fichier CSV en utilisant 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
SHELL

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

// 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
$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 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 Documentation
Documentation related to Library Quick Access

Questions Fréquemment Posées

Comment créer un fichier CSV avec C# ?

Vous pouvez créer un fichier CSV en C# en utilisant la bibliothèque IronXL. Après avoir installé le package IronXL, chargez un classeur Excel existant et utilisez la méthode SaveAsCsv pour le sauvegarder en tant que fichier CSV.

Quelles sont les étapes pour installer le package IronXL pour C# ?

Pour installer IronXL, vous pouvez soit le télécharger directement depuis le site web de Iron Software, soit utiliser le Gestionnaire de Packages NuGet dans Visual Studio. Dans le Gestionnaire de Packages NuGet, recherchez IronXL.Excel et cliquez sur 'Installer', ou utilisez la commande Install-Package IronXL.Excel dans la console.

Puis-je exporter des données d'un fichier Excel vers CSV en utilisant C# ?

Oui, en utilisant IronXL, vous pouvez exporter des données d'un fichier Excel au format CSV. Chargez le classeur Excel et utilisez la méthode SaveAsCsv pour exporter les données.

Quels sont les formats de fichiers pris en charge par la bibliothèque IronXL ?

IronXL prend en charge divers formats de fichiers, y compris .xlsx, .xls, .csv et .tsv, vous permettant de travailler avec une large gamme de types de fichiers Excel.

Comment puis-je manipuler des données Excel en utilisant une bibliothèque C# ?

Avec IronXL, vous pouvez manipuler des données Excel en utilisant ses fonctions complètes pour l'importation, l'exportation et le formatage des données, vous permettant un contrôle total sur les fichiers Excel en C#.

IronXL prend-il en charge la gestion des graphiques dans les fichiers Excel ?

Oui, IronXL prend en charge la gestion des graphiques, vous permettant de travailler et de gérer les graphiques dans les fichiers Excel facilement.

Quelles options de formatage de cellules sont disponibles dans la bibliothèque IronXL ?

IronXL fournit diverses options de formatage de cellules, y compris l'alignement du texte, la taille de la police et la couleur, ainsi que la personnalisation des quadrillages, vous aidant à formater les documents Excel selon vos besoins.

Où puis-je trouver une documentation API plus détaillée pour IronXL ?

Vous pouvez accéder à la documentation de référence API détaillée pour IronXL sur le site web de Iron Software dans la section Documentation de Référence API, qui fournit des ressources supplémentaires pour travailler avec les feuilles de calcul Excel.

Jordi Bardia
Ingénieur logiciel
Jordi est le plus compétent en Python, C# et C++, et lorsqu'il ne met pas à profit ses compétences chez Iron Software, il programme des jeux. Partageant les responsabilités des tests de produit, du développement de produit et de la recherche, Jordi apporte une immense valeur à l'amé...
Lire la suite