PNG
JPG
BMP
TIFF
XLS
Redact XLS Formats in C#
Native and high performance XLS document sensitive redaction information using server-side Aspose.Cells for .NET APIs, without the use of any software like Microsoft or Adobe PDF.
How to Redact XLS File Using C#
In order to redact XLS file, we’ll use Aspose.Cells for .NET API which is a feature-rich, powerful and easy to use document manipulation API for C# platform. Open NuGet package manager, search for Aspose.Cells and install. You may also use the following command from the Package Manager Console.
Command
PM> Install-Package Aspose.Cells
Steps to Redact XLS Files in C#
A basic document search and replace text in contents, comments or metadata with Aspose.Cells for .NET APIs can be done with just few lines of code.
- Load XLS file.
- Select the sheet.
- Create FindOptions object.
- Set Search Options
- Loop through each cell and use Find method.
- Save the workbook.
System Requirements
Our APIs are supported on all major platforms and Operating Systems. Before executing the code below, please make sure that you have the following prerequisites on your system.
- Microsoft Windows or a compatible OS with .NET Framework, .NET Core, Mono or Xamarin Platforms
- Development environment like Microsoft Visual Studio
- Add reference to the Aspose.Cells for .NET DLL in your project - Install from NuGet using the Download button above
Redact XLS Files - C#
Workbook wb = new Workbook("e:\test2\Input.xls");
Worksheet sheet = wb.Worksheets[0];
FindOptions opts = new FindOptions();
opts.LookInType = LookInType.Values;
opts.LookAtType = LookAtType.Contains;
opts.RegexKey = true;
Aspose.Cells.Cell cell = null;
do
{ //find only whole word and not part of any word.
cell = sheet.Cells.Find("\bKIM\b", cell, opts);
if (cell != null)
{
string celltext = cell.Value.ToString();
celltext = celltext.Replace("KIM", "^^^^^^^^^^");
cell.PutValue(celltext);
}
}
while (cell != null);
wb.Save("e:\test2\out1.xls");
// Find/Replace in whole workbook.
Workbook wb = new Workbook("e:\test2\Input.xls");
wb.Replace("\bKIM\b", "^^^^^^^^", new ReplaceOptions() { RegexKey = true });
wb.Save("e:\test2\output.xls");