-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSearchActions.vb
48 lines (41 loc) · 1.66 KB
/
SearchActions.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Imports DevExpress.Spreadsheet
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Namespace SpreadsheetDocServerAPIPart2
Public Module SearchActions
Public SimpleSearchValueAction As Action(Of Workbook) = AddressOf SimpleSearchValue
Public AdvancedSearchValueAction As Action(Of Workbook) = AddressOf AdvancedSearchValue
Private Sub SimpleSearchValue(ByVal workbook As Workbook)
' #Region "#SimpleSearch"
workbook.Calculate()
Dim worksheet As Worksheet = workbook.Worksheets("ExpenseReport")
workbook.Worksheets.ActiveWorksheet = worksheet
' Find and highlight cells that contain the word "holiday".
Dim searchResult As IEnumerable(Of Cell) = worksheet.Search("holiday")
For Each cell As Cell In searchResult
cell.Fill.BackgroundColor = Color.LightGreen
Next cell
' #End Region ' #SimpleSearch
End Sub
Private Sub AdvancedSearchValue(ByVal workbook As Workbook)
' #Region "#AdvancedSearch"
workbook.Calculate()
Dim worksheet As Worksheet = workbook.Worksheets("ExpenseReport")
workbook.Worksheets.ActiveWorksheet = worksheet
' 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 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
cell.Fill.BackgroundColor = Color.LightGreen
Next cell
' #End Region ' #AdvancedSearch
End Sub
End Module
End Namespace