Syncfusion.XlsIO.Base
Example 


Syncfusion.XlsIO Namespace > IWorksheet Interface : ImportDataGridView Method
DataGridView 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.

ImportDataGridView Method

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

Parameters

dataGridView
DataGridView 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 ImportDataGridView refer this link
Example
The following code illustrates how to Imports data from Microsoft System.Windows.Forms.DataGridView 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 DataGridView control
     DataGridView dataGridView = new DataGridView();
     
     //Get the data from GetDataTable method.
     dataGridView.DataSource = GetDataTable();
     
     //Import data from DataGridView control
     worksheet.ImportDataGridView(dataGridView, 1, 1, true, true);
     
     workbook.SaveAs("ImportDataGridView.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.4460.0.40

See Also