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.
Unfortunately, activation email could not send to your email. Please try again.

import range of cells from excel worksheet to gridcontrol

Thread ID:

Created:

Updated:

Platform:

Replies:

84360 Jun 30,2009 08:12 AM Jul 6,2009 11:13 AM Windows Forms 1
loading
Tags: GridControl
Bob
Asked On June 30, 2009 08:12 AM

import range of cells from excel worksheet to gridcontrol

Lingaraj S [Syncfusion]
Replied On July 6, 2009 11:13 AM

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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;