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.
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;
}
Discover how the import and export feature in the Syncfusion® Excel Library simplifies data management by seamlessly transferring data to and from Excel.
Import data from a DataTable to an Excel sheet, ensuring that all the data and data types are preserved properly.
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.
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.
Any type of array data can be imported to Excel when maintaining its data types.
When exporting data from Excel to a DataTable, the Excel data and data type are preserved by mapping Excel columns to DataTable columns.
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.
Discover valuable resources from our blogs and knowledge base articles to enhance your efficiency in importing and exporting data with Excel.
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Product Updates
Technical Support
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.
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.