Syncfusion.XlsIO.Base
Example 


Syncfusion.XlsIO Namespace > IWorksheet Interface > ImportDataTable Method : ImportDataTable(DataTable,IName,Boolean,Int32,Int32) Method
Data Table with desired data.
Represents named range IName. Bounds of data table should not greatfull than bounds of named range. i.e., Example NamedRange["A1:F6"] have a 6 Rows and 6 Columns. Also we should have DataTable rows and columns also same or lessthan named range.
TRUE if column names must also be imported. FALSE otherwise.
Represents row offset into named range to import.
Represents column offset into named range to import.

ImportDataTable(DataTable,IName,Boolean,Int32,Int32) Method

Imports data from System.Data.DataTable into the specified named range of current worksheet with row and column offset.
Syntax
'Declaration
 
Overloads Function ImportDataTable( _
   ByVal dataTable As DataTable, _
   ByVal namedRange As IName, _
   ByVal isFieldNameShown As Boolean, _
   ByVal rowOffset As Integer, _
   ByVal columnOffset As Integer _
) As Integer
'Usage
 
Dim instance As IWorksheet
Dim dataTable As DataTable
Dim namedRange As IName
Dim isFieldNameShown As Boolean
Dim rowOffset As Integer
Dim columnOffset As Integer
Dim value As Integer
 
value = instance.ImportDataTable(dataTable, namedRange, isFieldNameShown, rowOffset, columnOffset)

Parameters

dataTable
Data Table with desired data.
namedRange
Represents named range IName. Bounds of data table should not greatfull than bounds of named range. i.e., Example NamedRange["A1:F6"] have a 6 Rows and 6 Columns. Also we should have DataTable rows and columns also same or lessthan named range.
isFieldNameShown
TRUE if column names must also be imported. FALSE otherwise.
rowOffset
Represents row offset into named range to import.
columnOffset
Represents column offset into named range to import.

Return Value

Number of imported rows.
Remarks
This method is supported in ASP.NET Core, Xamarin, and UWP platforms from .NET Standard 2.0 onward. To know more about ImportDataTable refer this link
Example
The following code illustrates how to Imports data from System.Data.DataTable into the specified named range of current worksheet with row and column offset.
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 named range
     IName namedRange = worksheet.Names.Add("SampleInfo");
     namedRange.RefersToRange = worksheet.Range["A1:F6"];
     
     //Initialize DataTable and data get from SampleDataTable method
     DataTable table = SampleDataTable();
     
     //Import data from DataTable
     worksheet.ImportDataTable(table, namedRange, true, 1, 3);
     
     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