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.

Excel search with GemBox.Spreadsheet
Screenshot of Excel search with GemBox.Spreadsheet
Upload your file (Drag file here)
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

GemBox.Spreadsheet is a .NET component that enables you to read, write, edit, convert, and print spreadsheet files from your .NET applications using one simple API.

Download Buy