The Excel spreadsheets have minimized the efforts required to keep the huge data and perform complex calculations automatically. Alongside, Finding and replacing text in Excel files is one of the frequently performed operations in Excel file. Therefore, in this article, I will show you how to find and replace text in Excel files programmatically in C# with a few lines of code.

C# API for Finding and Replacing Text in Excel - Free Download

Aspose.Cells for .NET is a powerful API that allows you to completely automate the process of creating, editing, parsing and converting the Excel spreadsheet programmatically. The API also provides easy ways of finding and replacing text based on the plain text as well as regular expressions (regex). You can either download the API or install it in your application via NuGet Package Manager or Package Manager Console.

NuGet Package Manager

Find and replace text with regex in Excel

Package Manager Console

PM> Install-Package Aspose.Cells

Find and Replace Text in Excel using C#

The following is the simple recipe to find and replace text in an Excel workbook in C# using Aspose.Cells for .NET.

The following code sample shows how to find and replace text in Excel using C#.

C# Find and Replace Text in Excel with Regular Expression

You can also find and replace text that matches a particular pattern, such as Email IDs, SSN, etc. In order to do that, just set the ReplaceOptions.RegexKey property to true and call Workbook.Replace(String, String, ReplaceOptions) method.

The following code sample shows how to find and replace the text with regex in the Excel workbook in C#.

Conclusion

In this article, you have learned how to easily find and replace text in Excel files in C#. Furthermore, you have seen how to use a regular expression for finding and replacing text in Excel files.

Use Aspose.Cell for .NET for Free

Get a free temporary license of Aspose.Cells for .NET and enjoy its powerful features.

See also