Comment charger des feuilles de calcul existantes en C#

How to Load Existing Spreadsheets

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

CSV (Comma-Separated Values) file format is for tabular data where values are separated by commas, commonly used for data exchange. On the other hand, TSV (Tab-Separated Values) uses tabs to separate values, preferred when data contains commas.

The DataSet class in Microsoft's .NET is a part of the ADO.NET (ActiveX Data Objects for .NET) technology. It's often used in database-related applications and allows you to work with data from various sources like databases, XML, and more.

Data contained in Excel file formats such as XLSX, XLS, XLSM, XLTX, CSV, and TSV as well as a DataSet object can be loaded into an Excel spreadsheet using IronXL.

Quickstart: Load an Existing Spreadsheet Effortlessly

Using one simple method, you can load an existing Excel, CSV, or TSV file into a WorkBook with IronXL. Developers can quickly get started editing or extracting data by calling WorkBook.Load(...) for full Excel support, or LoadCSV(...) specifically for CSV formats.

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.

    IronXL.WorkBook workbook = IronXL.WorkBook.Load("sample.xlsx");
  3. Deploy to test on your live environment

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


Load Spreadsheet Example

Use the static method Load to load an existing Excel workbook. The method supports XLSX, XLS, XLSM, XLTX, CSV, and TSV file formats. In cases where the workbook is protected with a password, you can pass the password as the second parameter to the method. The method also accepts workbook data in the form of a byte array or a stream, where the dedicated FromByteArray and FromStream methods can be used, respectively.

:path=/static-assets/excel/content-code-examples/how-to/load-spreadsheet-load-spreadsheet.cs
using IronXL;

// Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV
WorkBook workBook = WorkBook.Load("sample.xlsx");
Imports IronXL

' Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV
Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
$vbLabelText   $csharpLabel

Load CSV file

While the Load method can read all available file formats, it is recommended to use the LoadCSV method specifically for CSV file formats for optimal handling.

:path=/static-assets/excel/content-code-examples/how-to/load-spreadsheet-load-csv.cs
using IronXL;

// Load CSV file
WorkBook workBook = WorkBook.LoadCSV("sample.csv");
Imports IronXL

' Load CSV file
Private workBook As WorkBook = WorkBook.LoadCSV("sample.csv")
$vbLabelText   $csharpLabel

Load DataSet

The DataSet class in Microsoft .NET is used for managing and working with data in a disconnected, in-memory representation. This DataSet can also be loaded into the workbook using the LoadWorkSheetsFromDataSet method. In the code example below, an empty DataSet is created; however, it's more common to instantiate the DataSet from a database query.

:path=/static-assets/excel/content-code-examples/how-to/load-spreadsheet-load-dataset.cs
using IronXL;
using System.Data;

// Create dataset
DataSet dataSet = new DataSet();

// Create workbook
WorkBook workBook = WorkBook.Create();

// Load DataSet
WorkBook.LoadWorkSheetsFromDataSet(dataSet, workBook);
Imports IronXL
Imports System.Data

' Create dataset
Private dataSet As New DataSet()

' Create workbook
Private workBook As WorkBook = WorkBook.Create()

' Load DataSet
WorkBook.LoadWorkSheetsFromDataSet(dataSet, workBook)
$vbLabelText   $csharpLabel

Questions Fréquemment Posées

Comment puis-je charger une feuille de calcul existante en .NET C# ?

Pour charger une feuille de calcul existante en .NET C#, utilisez la méthode Load d'IronXL. Cette méthode prend en charge plusieurs formats de fichiers, y compris XLSX, XLS, XLSM, XLTX, CSV, et TSV.

Quelle méthode devrais-je utiliser pour charger un fichier CSV ?

Pour une gestion optimale des formats de fichiers CSV, utilisez la méthode LoadCSV fournie par IronXL.

Comment puis-je gérer les classeurs Excel protégés par mot de passe ?

Vous pouvez charger des classeurs Excel protégés par mot de passe en utilisant IronXL en passant le mot de passe comme deuxième paramètre à la méthode Load.

Est-il possible de charger des données de classeur à partir d'un tableau d'octets ou d'un flux ?

Oui, IronXL permet de charger des données de classeur à partir d'un tableau d'octets en utilisant la méthode LoadFromByteArray, et à partir d'un flux en utilisant la méthode LoadFromStream.

Comment puis-je charger des données d'un DataSet dans un classeur Excel ?

Utilisez la méthode LoadWorkSheetsFromDataSet d'IronXL pour importer des données d'un DataSet dans un classeur Excel. Cette méthode crée une feuille de calcul par DataTable dans le DataSet.

Quels sont les avantages de l'utilisation de la classe DataSet en .NET ?

La classe DataSet en .NET fournit un moyen de gérer et de travailler avec des données sous une représentation déconnectée et en mémoire, ce qui est utile pour manipuler des données provenant de diverses sources telles que des bases de données et XML.

Quelles étapes sont nécessaires pour commencer à utiliser IronXL pour charger des feuilles de calcul ?

Pour commencer à utiliser IronXL, téléchargez la bibliothèque depuis NuGet, préparez votre fichier ou objet de données, et utilisez des méthodes comme Load et LoadWorkSheetsFromDataSet pour importer des données dans un objet classeur.

Chaknith Bin
Ingénieur logiciel
Chaknith travaille sur IronXL et IronBarcode. Il a une expertise approfondie en C# et .NET, aidant à améliorer le logiciel et à soutenir les clients. Ses idées issues des interactions avec les utilisateurs contribuent à de meilleurs produits, documentation et expérience globale.
Prêt à commencer?
Nuget Téléchargements 1,686,155 | Version : 2025.11 vient de sortir