Syncfusion.XlsIO.Base
Example 


GridView 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.

ImportGridView Method

Imports data from Microsoft System.Web.UI.WebControls.GridView into worksheet.
Syntax
'Declaration
 
Sub ImportGridView( _
   ByVal gridView As GridView, _
   ByVal firstRow As Integer, _
   ByVal firstColumn As Integer, _
   ByVal isImportHeader As Boolean, _
   ByVal isImportStyle As Boolean _
) 
'Usage
 
Dim instance As IWorksheet
Dim gridView As GridView
Dim firstRow As Integer
Dim firstColumn As Integer
Dim isImportHeader As Boolean
Dim isImportStyle As Boolean
 
instance.ImportGridView(gridView, firstRow, firstColumn, isImportHeader, isImportStyle)

Parameters

gridView
GridView 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 supported in ASP.NET Web Forms only. To know more about ImportDataGrid refer this link
Example
The following code illustrates how to Imports data from MS System.Web.UI.WebControls.GridView into worksheet with the specified row and column.
using Syncfusion.XlsIO;
using System;
using System.Data;
             
public partial class Sample : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
   GridView();
  }
  
  public void GridView()
  {
    ExcelEngine excelEngine = new ExcelEngine();
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2013;
    IWorkbook workbook = application.Workbooks.Create(1);
    IWorksheet worksheet = workbook.Worksheets[0];
    
    //Set value to the DataSource of GridView web control
    gridView.DataSource = GetDataTable();
    gridView.DataBind();
   
    //Import data from DataGrid control
    worksheet.ImportGridView(gridView, 1, 1, true,true);
            
    workbook.SaveAs("ImportGridView.xlsx", ExcelSaveType.SaveAsXLS, Response, ExcelDownloadType.PromptDialog);
    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