We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Syncfusion Feedback

Trusted by the world’s leading companies

Syncfusion Trusted Companies

Overview

The Syncfusion® .NET Excel (XlsIO) library provides support for exporting data to Excel from data sources such as data tables, arrays, collections, CSV, and TSV. It also allows exporting data from Excel to data tables, collections, and nested classes.

Exporting data to Excel works on .NET MAUI, ASP.NET Core, ASP.NET MVC, Blazor, Windows Forms, UWP, WinUI, WPF, and Xamarin platforms.

Import data to Excel code example

This example code shows how to import data from a data table to an Excel worksheet using Syncfusion® .NET Excel Library with just a few lines of code in C#.

// Initialize Excel engine and application.
using ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

// Create a workbook and worksheet.
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];

// Initialize and populate DataTable.
DataTable table = SampleDataTable();

// Import data from DataTable to the worksheet.
worksheet.ImportDataTable(table, true, 1, 1);

// Save the Excel document.
using FileStream outputStream = new FileStream("ImportDataTable.xlsx", FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);

// Method to create a sample DataTable.
private DataTable SampleDataTable()
{
    // Create DataTable with columns.
    DataTable table = new DataTable();
    table.Columns.Add("Dosage", typeof(int));
    table.Columns.Add("Drug", typeof(string));
    table.Columns.Add("Patient", typeof(string));
    table.Columns.Add("Date", typeof(DateTime));

    // Add sample data rows.
    table.Rows.Add(25, "Indocin", "David", DateTime.Now);
    table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
    table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
    table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
    table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);

    return table;
}

Key features of import and export

Discover how the import and export feature in the Syncfusion® Excel Library simplifies data management by seamlessly transferring data to and from Excel.

DataTable to Excels in .NET Excel.

DataTable to Excel

Import data from a DataTable to an Excel sheet, ensuring that all the data and data types are preserved properly.

DataColumn to Excel in .NET Excel.

DataColumn to Excel

Programmatically select single or multiple pages from the document based on criteria such as page number and content and save them as a single PDF document.

Collection Objects to Excel in .NET Excel.

Collection Objects to Excel

Import data from collection objects into Excel, ensuring that the data is accurately transferred when maintaining the data types of the properties from the objects.

Array to Excel in .NET Excel.

Array to Excel

Any type of array data can be imported to Excel when maintaining its data types.

Excel to DataTable in .NET Excel.

Excel to DataTable

When exporting data from Excel to a DataTable, the Excel data and data type are preserved by mapping Excel columns to DataTable columns.

Excel to Collection Objects in .NET Excel.

Excel to Collection Objects

Import data from Excel into collection objects, ensuring that the data is accurately transferred and organized according to the object type while maintaining the integrity of the original Excel data.

Explore import and export references

Discover valuable resources from our blogs and knowledge base articles to enhance your efficiency in importing and exporting data with Excel.

How to Export Data from Excel to DataTable with Customization in C

Blog

How to Export Data from Excel to DataTable with Customization in C#

Easy Steps to Export HTML Tables to an Excel Worksheet in C

Blog

Easy Steps to Export HTML Tables to an Excel Worksheet in C#

Export Data from Collections to Excel and Group It in C

Blog

Export Data from Collections to Excel and Group It in C#

6 Easy Ways to Export Data to Excel in C

Blog

6 Easy Ways to Export Data to Excel in C#

Export DataTable to Excel with formatting in C, VB.NET

Knowledge base

Export DataTable to Excel with formatting in C#, VB.NET

Export Excel to DataTable in C, VB.NET

Knowledge base

Export Excel to DataTable in C#, VB.NET

Export data to Excel in ASP.NET MVC

Knowledge base

Export data to Excel in ASP.NET MVC

Export data to Excel in WPF

Knowledge base

Export data to Excel in WPF

Export data to Excel in Xamarin.Forms

Knowledge base

Export data to Excel in Xamarin.Forms

Syncfusion .NET Excel Library Resources

Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.

Frequently Asked Questions

Importing data into Excel involves retrieving data from various sources like arrays, data tables, grid views, or collection objects and storing it within Excel while maintaining its structure and integrity.

When importing data into Excel, the cells will be populated according to the number of rows and columns in the data source. To prevent overlapping existing data, it is necessary to provide a starting row and column index that defines an empty cell range. Exporting the data will not impact any other data within the Excel file.

Microsoft Excel supports a maximum of 1,048,576 rows and 16,384 columns for a single worksheet. XlsIO supports the same number of rows and columns when importing and exporting data.

Exporting data from Excel involves converting the data into common formats like data tables or collection objects, making it usable in other applications.

Yes. XlsIO supports importing data from various data sources into the same Excel file.

No. XlsIO performs Excel manipulation without any Microsoft Office dependencies.

Our Customers Love Us

Having an excellent set of tools and a great support team, Syncfusion® reduces customers’ development time.
Here are some of their experiences.

Rated by users across the globe

Want to create, View, and edit Excel files in C# or VB.NET?

Start a free 30-day evaluation today!
DOWNLOAD FREE TRIAL

No credit card required.

Mobile Free Evaluation Section

Awards

Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion® is proud to hold the following industry awards.

Scroll up icon