ExcelWorksheetSettings Class
Contains options used to select data from the specified worksheet.
Namespace: DevExpress.DataAccess.Excel
Assembly: DevExpress.DataAccess.v24.1.dll
NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap
Declaration
Remarks
The ExcelSourceOptions.ImportSettings property exposed by the ExcelSourceOptions class allows you to specify the approach used to import data from a workbook. For instance, you can select all data from the specified worksheet or specify the required cell range. To select all data from the specified worksheet, create the ExcelWorksheetSettings object and specify the worksheet name using the ExcelWorksheetSettings.WorksheetName property. To select a range of cells from the specified worksheet, you also need to specify the ExcelWorksheetSettings.CellRange property.
The following example shows how to select the A1:F20 range of cells located on the Sheet1 worksheet.
ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings();
worksheetSettings.WorksheetName = "Sheet1";
worksheetSettings.CellRange = "A1:F20";
As an alternative, you can specify the sheet and the cell range using only the ExcelWorksheetSettings.CellRange property.
ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings();
worksheetSettings.CellRange = "Sheet1!A1:F20";
Example
The following code creates the ExcelDataSource and selects a cell range in the SalesPerson
worksheet.
ExcelDataSource excelDataSource = new ExcelDataSource();
excelDataSource.Name = "Excel Data Source";
excelDataSource.FileName = HostingEnvironment.MapPath(@"~/App_Data/ExcelDataSource.xlsx");
ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings("SalesPerson", "A1:L2000");
excelDataSource.SourceOptions = new ExcelSourceOptions(worksheetSettings);
excelDataSource.Fill();