Search in Excel Using C# and VB.NET
The following example shows how you can search text in a spreadsheet file with C# and VB.NET using the CellRange.FindText
method.
The example will display all the occurrences of searched text in the targeted Excel column.

using System;
using GemBox.Spreadsheet;
class Program
{
static void Main()
{
// If using the Professional version, put your serial key below.
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
var workbook = ExcelFile.Load("%InputFileName%");
var worksheet = workbook.Worksheets.ActiveWorksheet;
var searchText = "Apollo";
foreach (var cell in worksheet.Cells.FindAllText(searchText))
Console.WriteLine($"Text was found in cell '{cell.Name}' (\"{cell.StringValue}\").");
}
}
Imports System
Imports GemBox.Spreadsheet
Module Program
Sub Main()
' If using the Professional version, put your serial key below.
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
Dim workbook = ExcelFile.Load("%InputFileName%")
Dim worksheet = workbook.Worksheets.ActiveWorksheet
Dim searchText = "Apollo"
For Each cell In worksheet.Cells.FindAllText(searchText)
Console.WriteLine($"Text was found in cell '{cell.Name}' (""{cell.StringValue}"").")
Next
End Sub
End Module
See also
Next steps
Published: December 13, 2018 | Modified: May 15, 2023 | Author: Mario Zorica