Back to Devexpress

SearchOptions.SearchBy Property

officefileapi-devexpress-dot-spreadsheet-dot-searchoptions.md

latest6.6 KB
Original Source

SearchOptions.SearchBy Property

Gets or sets the direction of the search.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public SearchBy SearchBy { get; set; }
vb
Public Property SearchBy As SearchBy

Property Value

TypeDescription
SearchBy

One of the SearchBy enumeration values indicating whether to search by rows or by columns.

|

Available values:

NameDescription
Rows

Searches each row from left to right. All the cells in the current row will be traversed from left to right before moving to the next row.

| | Columns |

Searches each column from top to bottom. All the cells in the current column will be traversed before moving to the next column.

|

Remarks

For more information about how to perform a search in the document, see Find and Replace.

Example

The example below demonstrates how to perform a search with the specified options in the active worksheet and highlight all matching cells.

View Example

vb
workbook.LoadDocument("Documents\ExpenseReport.xlsx")
workbook.Calculate()
Dim worksheet As Worksheet = workbook.Worksheets(0)

' Specify the search term.
Dim searchString As String = Date.Today.ToString("d")

' Specify search options.
Dim options As New SearchOptions()
options.SearchBy = SearchBy.Columns
options.SearchIn = SearchIn.Values
options.MatchEntireCellContents = True

' Find all cells containing today's date and paint them light-green.
Dim searchResult As IEnumerable(Of Cell) = worksheet.Search(searchString, options)
For Each cell As Cell In searchResult
    cell.Fill.BackgroundColor = Color.LightGreen
Next cell
csharp
workbook.LoadDocument("Documents\\ExpenseReport.xlsx");
workbook.Calculate();
Worksheet worksheet = workbook.Worksheets[0];

// Specify the search term.
string searchString = DateTime.Today.ToString("d");

// Specify search options.
SearchOptions options = new SearchOptions();
options.SearchBy = SearchBy.Columns;
options.SearchIn = SearchIn.Values;
options.MatchEntireCellContents = true;

// Find all cells containing today's date and paint them light-green.
IEnumerable<Cell> searchResult = worksheet.Search(searchString, options);
foreach (Cell cell in searchResult)
    cell.Fill.BackgroundColor = Color.LightGreen;

The following code snippets (auto-collected from DevExpress Examples) contain references to the SearchBy property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_API_Part02/SpreadsheetActions/SearchActions.cs#L44

csharp
SearchOptions options = new SearchOptions();
options.SearchBy = SearchBy.Columns;
options.SearchIn = SearchIn.Values;

wpf-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/SearchActions.cs#L46

csharp
SearchOptions options = new SearchOptions();
options.SearchBy = SearchBy.Columns;
options.SearchIn = SearchIn.Values;

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/SearchActions.cs#L39

csharp
SearchOptions options = new SearchOptions();
options.SearchBy = SearchBy.Columns;
options.SearchIn = SearchIn.Values;

winforms-spreadsheetcontrol-api-part-2/VB/SpreadsheetControl_API_Part02/SpreadsheetActions/SearchActions.vb#L41

vb
Dim options As New SearchOptions()
options.SearchBy = SearchBy.Columns
options.SearchIn = SearchIn.Values

wpf-spreadsheetcontrol-api-part-2/VB/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/SearchActions.vb#L43

vb
Dim options As New SearchOptions()
options.SearchBy = SearchBy.Columns
options.SearchIn = SearchIn.Values

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/SearchActions.vb#L36

vb
Dim options As New SearchOptions()
options.SearchBy = SearchBy.Columns
options.SearchIn = SearchIn.Values

See Also

Range.Search*

Worksheet.Search*

IWorkbook.Search*

SearchOptions Class

SearchOptions Members

DevExpress.Spreadsheet Namespace