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 range of cells from excel worksheet to gridcontrol

import range of cells from excel worksheet to gridcontrol

1 Reply

LS Lingaraj S Syncfusion Team July 6, 2009 03:13 PM UTC

Hi,

Thank you for your interest in SYncfusion product.

The ExcelToGrid method from the GridExcelConverterControl will get the range of datas from the excel sheet and assign the value of each cell from the excel to the grid along with it look and feel, like its row width, and cell style, this has been handled internally in the GridExcelConverterControl class.
If you want to import the data from the excel range, you can handle it by adding it to a DataTable and populating the datas from the DataTable will retains the look and feel of the control.

Please refer the code below:
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("../../Sample1.xls");
IWorksheet sheet = workbook.Worksheets[0];
// Specify the Range In this the Used range used.
DataTable dt = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames | ExcelExportDataTableOptions.DetectColumnTypes);
this.gridControl1.RowCount = dt.Rows.Count;
this.gridControl1.ColCount = dt.Columns.Count;
this.gridControl1.PopulateValues(GridRangeInfo.Cells(1, 1, dt.Rows.Count, dt.Columns.Count), dt);


Please let me know if you have any queries.

Regards,
Lingaraj S.

Loader.
Live Chat Icon For mobile
Up arrow icon