Cómo leer archivos CSV en C# usando IronXL

Read a CSV File in C#

This article was translated from English: Does it need improvement?
Translated
View the article in English

When you need to read CSV files in C#, IronXL is an easy answer. You can read a CSV file with commas, or any other delimiter, as seen in the code segments below.

Quickstart: Load and convert a CSV file using IronXL in one line

This example shows how easy it is to read a CSV file using IronXL’s LoadCSV method and save it as an Excel workbook, letting you get started in seconds with minimal code.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. Copy and run this code snippet.

    WorkBook wb = WorkBook.LoadCSV("data.csv", ExcelFileFormat.XLSX, listDelimiter: ","); wb.SaveAs("output.xlsx");
  3. Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    arrow pointer

Reading CSV Files in .NET Applications

  • Install a C# library for Reading CSV Files (IronXL)
  • Read CSV files in C#
  • Specify file format and delimiter
How To Work related to Read a CSV File in C#

Step 1

1. Install the IronXL Library

Before you can make use of IronXL to read CSV files in MVC or ASP or dotnet core, you need to install it first. Here is a quick walk-through.

  • In Visual Studio, select the Project menu
  • Manage NuGet Packages
  • Search for IronXL.Excel
  • Install
IronXL.Excel NuGet Package
Figure 1 - IronXL.Excel NuGet Package

Or Download from the Iron Software website, here: https://ironsoftware.com/csharp/excel/packages/IronXL.zip


How to Tutorial

2. Read CSV Files Programmatically

Now for the project!

Add the IronXL Namespace

// This namespace is required to access the IronXL functionalities
using IronXL;
// This namespace is required to access the IronXL functionalities
using IronXL;
' This namespace is required to access the IronXL functionalities
Imports IronXL
$vbLabelText   $csharpLabel

Add code to read a CSV file programmatically with IronXL and C#

:path=/static-assets/excel/content-code-examples/how-to/csharp-read-csv-read.cs
// Load the CSV file into a WorkBook object, specifying the file path, format, and delimiter
WorkBook workbook = WorkBook.LoadCSV("Read_CSV_Ex.csv", fileFormat: ExcelFileFormat.XLSX, listDelimiter: ",");

// Access the default worksheet within the loaded workbook
WorkSheet ws = workbook.DefaultWorkSheet;

// Save the workbook as an Excel file with a specified name
workbook.SaveAs("Csv_To_Excel.xlsx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
A CSV file opened in Notepad
Figure 2 - A CSV file opened in Notepad

A Workbook object is created. The LoadCSV method of the Workbook object is then used to specify the name of the CSV file to be read, the format to read it into, and what the delimiter is for the file. In this case, a comma is used as a separator.

A Worksheet object is then created. This is where the contents of the CSV file will be placed. Then the file is saved under a new name and format.

The CSV file opened in Excel
Figure 3 - The CSV file opened in Excel

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 2. Read CSV Files Programmatically

Preguntas Frecuentes

¿Cómo puedo leer un archivo CSV en C# sin usar Interop?

Puedes leer un archivo CSV en C# sin usar Interop utilizando la biblioteca IronXL. Primero, instala IronXL a través del Administrador de paquetes NuGet en Visual Studio. Luego, usa el método WorkBook.LoadCSV para cargar el archivo CSV en un objeto WorkBook.

¿Qué pasos están involucrados en la lectura de un archivo CSV usando IronXL en C#?

Para leer un archivo CSV usando IronXL, primero instala la biblioteca IronXL. Luego, crea un nuevo proyecto en C#, agrega el espacio de nombres using IronXL;, y usa el método WorkBook.LoadCSV para cargar y manipular los datos del archivo CSV.

¿Puede IronXL manejar archivos CSV con diferentes delimitadores?

Sí, IronXL te permite especificar diferentes delimitadores al leer archivos CSV. Puedes ajustar el delimitador configurándolo en las opciones del método LoadCSV.

¿Cómo guardo un archivo CSV como un archivo de Excel en C#?

Después de cargar el archivo CSV en un objeto WorkBook con IronXL, puedes usar el método SaveAs para guardarlo como un archivo de Excel en el formato deseado, como XLSX.

¿Por qué usar IronXL en lugar de Microsoft Interop para operaciones CSV en C#?

IronXL se prefiere sobre Microsoft Interop para operaciones CSV en C# porque no requiere que Excel esté instalado en el servidor. Proporciona una forma más eficiente y simple de manejar archivos CSV dentro de aplicaciones C#.

¿Cómo especifico la hoja de trabajo para manipular en un archivo CSV usando IronXL?

Cuando cargas un archivo CSV usando IronXL, se almacena en un objeto WorkBook. Puedes acceder y manipular los datos usando el objeto WorkSheet predeterminado, que representa los contenidos del archivo CSV.

¿Es posible integrar funcionalidades de lectura CSV en aplicaciones ASP.NET usando IronXL?

Sí, puedes integrar funcionalidades de lectura CSV en aplicaciones ASP.NET o .NET Core usando IronXL instalando la biblioteca y utilizando sus métodos para cargar, leer y manipular datos CSV.

¿Dónde puedo encontrar la Documentación de Referencia del API de IronXL?

La Documentación de Referencia de la API de IronXL está disponible en el sitio web de Iron Software. Proporciona información detallada sobre todos los métodos disponibles, incluidos los de lectura y manipulación de archivos CSV.

¿Cuál es el propósito del método LoadCSV en IronXL?

El método LoadCSV en IronXL se utiliza para importar datos CSV en un objeto WorkBook, permitiéndote manipular e interactuar con los datos como si estuvieran en un formato de Excel.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 1,686,155 | Versión: 2025.11 recién lanzado