Back to Devexpress

Worksheet.Search(String, SearchOptions) Method

officefileapi-devexpress-dot-spreadsheet-dot-worksheet-dot-search-x28-system-dot-string-devexpress-dot-spreadsheet-dot-searchoptions-x29.md

latest7.7 KB
Original Source

Worksheet.Search(String, SearchOptions) Method

Performs a search in the worksheet using specified options.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
IEnumerable<Cell> Search(
    string text,
    SearchOptions options
)
vb
Function Search(
    text As String,
    options As SearchOptions
) As IEnumerable(Of Cell)

Parameters

NameTypeDescription
textString

A String representing the search text.

| | options | SearchOptions |

A SearchOptions instance containing required search options.

|

Returns

TypeDescription
IEnumerable<Cell>

An object implementing the IEnumerable interface which is the collection of cells that match the search term.

|

Remarks

To perform a search in the specific cell range or the entire document, use the CellRange.Search or IWorkbook.Search method. Use the CellRange.Value property to replace values in cells that match the search term.

For more information about the search functionality in the SpreadsheetControl, refer to the Find and Replace article.

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 Search(String, SearchOptions) method.

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#L49

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

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

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

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

csharp
// Find and highlight all cells that contain today's date.
IEnumerable<Cell> searchResult = worksheet.Search(searchString, options);
foreach (Cell cell in searchResult)

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

vb
' 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

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

vb
' 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

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

vb
' Find and highlight all cells that contain today's date.
Dim searchResult As IEnumerable(Of Cell) = worksheet.Search(searchString, options)
For Each cell As Cell In searchResult

See Also

Find and Replace

Worksheet Interface

Worksheet Members

DevExpress.Spreadsheet Namespace