We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Import Excel to GridDataBoundGrid

Hello.
How can I import the excel file to GridDataBoundGrid?

I found below ...


Syncfusion.GridExcelConverter.GridExcelConverterControl gecc = new Syncfusion.GridExcelConverter.GridExcelConverterControl();
gecc.ExcelToGrid(@"D:\excelTest.xls", this.gridDataBoundGrid1.Model);

But it import only one line at once.
If there are 100 or 1000 lines, I should run 100 or 1000 times.
Is there any way to import all data at once?
Please give me an advice.
Thank you.

1 Reply

RK Ranjeet Kumar Syncfusion Team December 2, 2009 10:18 AM UTC

Hi Chin,
Thanks for using Syncfusion Products.

ExportDataTable() method of Syncfusion.XlsIO.IWorksheet object may be used to import all the data from the excel sheet
into Syncfusion's gridDataBoundGrid control as shown below with the help of attached sample codes. To execute the codes we are handling button4_Click event.

//Event button4_Click
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Files(*.xls)|*.xls";
openFileDialog.DefaultExt = ".xls";

if (openFileDialog.ShowDialog() == DialogResult.OK)
{


ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
IWorkbook myWorkbook = excelEngine.Excel.Workbooks.Open(openFileDialog.FileName);
IWorksheet mySheet = myWorkbook.Worksheets[0];


// Import the contents of the Spreadsheet to a DataTable
DataTable dt = mySheet.ExportDataTable(1, 1, mySheet.UsedRange.End.Row, mySheet.UsedRange.End.Column, ExcelExportDataTableOptions.ColumnNames);


//Setting the datasource of the GridDataBoundGrid.
this.gridDataBoundGrid1.DataSource = dt;

excelEngine.ThrowNotSavedOnDestroy = false;
excelEngine.Dispose();
}



Please find the sample from the following link in which this code has been implemented.

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=ImportExcelToGDBG1284456829.zip

Please, do let me know if you have any query.


Regards
Ranjeet

Loader.
Live Chat Icon For mobile
Up arrow icon