Wednesday, 19 September 2012 01:15

Find and Highlight-Find and Highlight Data in Excel with C#, VB.NET

Written by  support iceblue
Rate this item
(0 votes)

Find function in Excel enables developers/programmers to find appointed data in Excel worksheet, and highlight function makes the data founded more observably. Find and highlight function gives developers and programmers more convenience of analyzing the data. This section demonstrates a clear introduction of find and highlight data in Excel worksheet via a .NET Excel component with C#, VB.NET.

Spire.XLS for .NET, as a .NET Excel component, enables users to quickly and easily find and highlight data in excel file. By calling Worksheet class method: public CellRange[] FindAllNumber(double doubleValue, bool formulaValue), users can find a certain value in cell range and then, highlight the value by setting the style property CellRange.Style.Color.

Please download Spire.XLS for .NET and install it on your system, add Spire.XLS.dll as reference in the downloaded Bin folder thought the below path: “…\Spire.XLS\Bin\NET4.0\ Spire.XLS.dll”. And then, preview the effect of find and highlight task as below picture:

This is the example of Excel Find and Highlight with C#, VB.NET

Find and Highlight Excel Data

[C#]
using Spire.Xls;

namespace fandh
{
    class Program
    {
        static void Main(string[] args)
        {
            //load an excel file from system
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"D:\my file\FandH.xlsx", ExcelVersion.Version2010);

            //find and highlight excel data
            Worksheet sheet = workbook.Worksheets[0];
            foreach (CellRange range in sheet.FindAllNumber(1502,true))
            {
                range.Style.Color = Color.LawnGreen;
            }
            //save and launch the project
            workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("result.xlsx");

        }
    }
}
[VB.NET]
Imports Spire.Xls

Namespace fandh
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            'load an excel file from system
            Dim workbook As Workbook = New Workbook
            workbook.LoadFromFile("D:\my file\FandH.xlsx", ExcelVersion.Version2010)
            'find and highlight excel data
            Dim sheet As Worksheet = workbook.Worksheets(0)
            For Each range As CellRange In sheet.FindAllNumber(1502, true)
                range.Style.Color = Color.LawnGreen
            Next
            'save and launch the project
            workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010)
            System.Diagnostics.Process.Start("result.xlsx")
        End Sub
    End Class
End Namespace

Spire.XLS supplies an easy way to find and highlight excel data, and it also supports find and replace data in Excel. It enables developers/programmers to fast generate, open, view, edit, save and print Excel files for .NET, Silverlight and WPF. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight.

Additional Info

  • tutorial_title: Find and Highlight Data
Last modified on Wednesday, 08 January 2014 02:50