Saltar al pie de página
USANDO IRONXL

Crear un archivo CSV usando 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 Crear un archivo CSV usando 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

Preguntas Frecuentes

¿Cómo creo un archivo CSV usando C#?

Puedes crear un archivo CSV en C# utilizando la biblioteca IronXL. Después de instalar el paquete IronXL, carga un libro de Excel existente y utiliza el método SaveAsCsv para guardarlo como un archivo CSV.

¿Qué pasos están involucrados en la instalación del paquete IronXL para C#?

Para instalar IronXL, puedes descargarlo directamente desde el sitio web de Iron Software o usar el Administrador de Paquetes NuGet en Visual Studio. En el Administrador de Paquetes NuGet, busca IronXL.Excel y haz clic en 'Instalar', o usa el comando Install-Package IronXL.Excel en la consola.

¿Puedo exportar datos de un archivo de Excel a CSV usando C#?

Sí, usando IronXL, puedes exportar datos de un archivo de Excel a un formato CSV. Carga el libro de Excel y utiliza el método SaveAsCsv para exportar los datos.

¿Qué formatos de archivo son compatibles con la biblioteca IronXL?

IronXL admite varios formatos de archivo, incluidos .xlsx, .xls, .csv y .tsv, lo que te permite trabajar con una amplia gama de tipos de archivos Excel.

¿Cómo puedo manipular datos de Excel usando una biblioteca C#?

Con IronXL, puedes manipular datos de Excel usando sus funciones completas para importación, exportación y formato de datos, dándote control total sobre los archivos Excel en C#.

¿IronXL admite la gestión de gráficos en archivos de Excel?

Sí, IronXL admite la gestión de gráficos, lo que te permite trabajar y gestionar gráficos en archivos de Excel sin problemas.

¿Qué opciones de formato de celda están disponibles en la biblioteca IronXL?

IronXL proporciona varias opciones de formato de celda, que incluyen alineación de texto, tamaño de fuente y color, así como personalización de líneas de cuadrícula, ayudándote a dar formato a documentos de Excel según sea necesario.

¿Dónde puedo encontrar más documentación detallada del API para IronXL?

Puedes acceder a la documentación detallada de referencia del API para IronXL en el sitio web de Iron Software en la sección Documentación de Referencia del API, que proporciona recursos adicionales para trabajar con hojas de cálculo Excel.

Jordi Bardia
Ingeniero de Software
Jordi es más competente en Python, C# y C++. Cuando no está aprovechando sus habilidades en Iron Software, está programando juegos. Compartiendo responsabilidades para pruebas de productos, desarrollo de productos e investigación, Jordi agrega un valor inmenso a la mejora continua del producto. La experiencia variada lo mantiene ...
Leer más