How to Load Existing Spreadsheets

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.


Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green 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

Frequently Asked Questions

How can I load an existing spreadsheet in .NET C#?

To load an existing spreadsheet in .NET C#, use IronXL's Load method. This method supports multiple file formats including XLSX, XLS, XLSM, XLTX, CSV, and TSV.

What method should I use to load a CSV file?

For optimal handling of CSV file formats, use the LoadCSV method provided by IronXL.

How can I handle password-protected Excel workbooks?

You can load password-protected Excel workbooks using IronXL by passing the password as a second parameter to the Load method.

Is it possible to load workbook data from a byte array or stream?

Yes, IronXL allows loading workbook data from a byte array using the LoadFromByteArray method, and from a stream using the LoadFromStream method.

How can I load data from a DataSet into an Excel workbook?

Use IronXL's LoadWorkSheetsFromDataSet method to import data from a DataSet into an Excel workbook. This method creates one worksheet per DataTable in the DataSet.

What are the benefits of using the DataSet class in .NET?

The DataSet class in .NET provides a way to manage and work with data in a disconnected, in-memory representation, which is useful for manipulating data from various sources such as databases and XML.

What steps are required to begin using IronXL to load spreadsheets?

To begin using IronXL, download the library from NuGet, prepare your file or data object, and use methods like Load and LoadWorkSheetsFromDataSet to import data into a workbook object.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.