Syncfusion.XlsIO.Base
Example 


Syncfusion.XlsIO Namespace > IWorksheet Interface : ImportDataGrid(DataGrid,Int32,Int32,Boolean,Boolean) Method
DataGrid with datasource.
Represents the first row of the worksheet to import.
Represents the first column of the worksheet to import.
TRUE if header must be imported. FALSE otherwise.
TRUE if row style must be imported. FALSE otherwise.

ImportDataGrid(DataGrid,Int32,Int32,Boolean,Boolean) Method

Imports data from Microsoft System.Windows.Forms.DataGrid into worksheet.
Syntax
'Declaration
 
Sub ImportDataGrid( _
   ByVal dataGrid As DataGrid, _
   ByVal firstRow As Integer, _
   ByVal firstColumn As Integer, _
   ByVal isImportHeader As Boolean, _
   ByVal isImportStyle As Boolean _
) 
'Usage
 
Dim instance As IWorksheet
Dim dataGrid As DataGrid
Dim firstRow As Integer
Dim firstColumn As Integer
Dim isImportHeader As Boolean
Dim isImportStyle As Boolean
 
instance.ImportDataGrid(dataGrid, firstRow, firstColumn, isImportHeader, isImportStyle)

Parameters

dataGrid
DataGrid with datasource.
firstRow
Represents the first row of the worksheet to import.
firstColumn
Represents the first column of the worksheet to import.
isImportHeader
TRUE if header must be imported. FALSE otherwise.
isImportStyle
TRUE if row style must be imported. FALSE otherwise.
Remarks
This method is only supported in Windows Form platform. To know more about ImportDataGrid refer this link
Example
The following code illustrates how to Imports data from Microsoft System.Windows.Forms.DataGrid into worksheet with the specified row and column.
using Syncfusion.XlsIO;
using System.Windows.Forms;
using System.Data;
             
public partial class Form1 : Form
{
  public Form1()
  {
     InitializeComponent();
     ExcelEngine excelEngine = new ExcelEngine();
     IApplication application = excelEngine.Excel;
     application.DefaultVersion = ExcelVersion.Excel2013;
     IWorkbook workbook = application.Workbooks.Create(1);
     IWorksheet worksheet = workbook.Worksheets[0];
     
     //Initialize DataGrid control
     DataGrid dataGrid = new DataGrid();
     dataGrid.DataSource = GetDataTable();
     
     //Import data from DataGrid control
     worksheet.ImportDataGrid(dataGrid, 1, 1, true, true);
     
     workbook.SaveAs("ImportDataGrid.xlsx");
     workbook.Close();
     excelEngine.Dispose();
  } 
  
  static DataTable GetDataTable()
  {
    // 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