Syncfusion.XlsIO.Base
Example 


Syncfusion.XlsIO Namespace > IWorksheet Interface > ImportDataTable Method : ImportDataTable(DataTable,Int32,Int32,Boolean) Method
Data Table with desired data.
First row from where the data should be imported.
First column from where the data should be imported.
TRUE if data table must be serialized directly on save.

ImportDataTable(DataTable,Int32,Int32,Boolean) Method

Imports data from a System.Data.DataTable into a worksheet with the specified row and column along with save option.
Syntax
'Declaration
 
Overloads Function ImportDataTable( _
   ByVal dataTable As DataTable, _
   ByVal firstRow As Integer, _
   ByVal firstColumn As Integer, _
   ByVal importOnSave As Boolean _
) As Integer
'Usage
 
Dim instance As IWorksheet
Dim dataTable As DataTable
Dim firstRow As Integer
Dim firstColumn As Integer
Dim importOnSave As Boolean
Dim value As Integer
 
value = instance.ImportDataTable(dataTable, firstRow, firstColumn, importOnSave)

Parameters

dataTable
Data Table with desired data.
firstRow
First row from where the data should be imported.
firstColumn
First column from where the data should be imported.
importOnSave
TRUE if data table must be serialized directly on save.

Return Value

Number of imported rows.
Remarks
We request you to use this method to improve performance and reduce memory consumption while dealing with large data. To know more about ImportDataTable refer this link. This method is supported in ASP.NET Core, Xamarin, and UWP platforms from .NET Standard 2.0 onward.
Example
The following code illustrates how to Imports data from a System.Data.DataTable into a worksheet with the specified row and column along with save option.
using Syncfusion.XlsIO;
using System.Data;
             
class Example
{
  static void Main()
  {
     ExcelEngine excelEngine = new ExcelEngine();
     IApplication application = excelEngine.Excel;
     application.DefaultVersion = ExcelVersion.Excel2013;
     IWorkbook workbook = application.Workbooks.Create(1);
     IWorksheet worksheet = workbook.Worksheets[0];
     
     //Initialize DataTable and data get from SampleDataTable method
     DataTable table = SampleDataTable();
     
     //Import data from DataTable
     worksheet.ImportDataTable(table, 1, 1, true);
     
     workbook.SaveAs("ImportDataTable.xlsx");
     workbook.Close();
     excelEngine.Dispose();
  } 
  
  static DataTable SampleDataTable()
  {
    // Here we create a three columns
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Item", typeof(string));
    table.Columns.Add("Name", typeof(string));
            
    // Here we add four DataRows
    table.Rows.Add(1, "Soap", "David");
    table.Rows.Add(2, "Paste", "Sam");
    table.Rows.Add(3, "Cream", "Christoff");
    table.Rows.Add(4, "Powder", "Janet");
    return table;
  }
}
AssemblyVersion

Syncfusion.XlsIO.Base: 16.4460.0.40

See Also