Syncfusion.XlsIO.Base
Example 


Syncfusion.XlsIO Namespace > IWorksheet Interface > ImportDataView Method : ImportDataView(DataView,Boolean,Int32,Int32,Boolean) Method
DataView with desired data.
TRUE if column names must be imported. FALSE otherwise.
First row from where the data should be imported.
First column from where the data should be imported.
Indicates whether XlsIO should preserve column types from DataReader. By default, preserve type is FALSE. i.e., Setting it to True will import data based on column type, otherwise will import based on value type.

ImportDataView(DataView,Boolean,Int32,Int32,Boolean) Method

Imports data from a System.Data.DataView into a worksheet with the specified range and preserve type.
Syntax
'Declaration
 
Overloads Function ImportDataView( _
   ByVal dataView As DataView, _
   ByVal isFieldNameShown As Boolean, _
   ByVal firstRow As Integer, _
   ByVal firstColumn As Integer, _
   ByVal bPreserveTypes As Boolean _
) As Integer
'Usage
 
Dim instance As IWorksheet
Dim dataView As DataView
Dim isFieldNameShown As Boolean
Dim firstRow As Integer
Dim firstColumn As Integer
Dim bPreserveTypes As Boolean
Dim value As Integer
 
value = instance.ImportDataView(dataView, isFieldNameShown, firstRow, firstColumn, bPreserveTypes)

Parameters

dataView
DataView with desired data.
isFieldNameShown
TRUE if column names must be imported. FALSE otherwise.
firstRow
First row from where the data should be imported.
firstColumn
First column from where the data should be imported.
bPreserveTypes
Indicates whether XlsIO should preserve column types from DataReader. By default, preserve type is FALSE. i.e., Setting it to True will import data based on column type, otherwise will import based on value type.

Return Value

Number of imported rows.
Remarks
This method is not supported in UWP, Xamarin platforms. To know more about ImportDataView refer this link
Example
The following code illustrates how to Imports data from a System.Data.DataView into worksheet with the specified row and column.
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 of DataTable get from SampleDataTable method
     DataTable table = SampleDataTable();
     
     //Initialize dataview of datatable
     DataView view = table.DefaultView;
  
     //Import data from DataView
     worksheet.ImportDataView(view, true, 1, 1, true);
     
     workbook.SaveAs("ImportDataView.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.3460.0.29

See Also