Watermarks are one of the ways to protect Excel files from being used illegally. Often, a watermark defines the ownership of the copyrighted content. In this article, you will learn about adding watermarks to Excel files programmatically. Particularly, the article will cover how to add watermark to Excel worksheets using C#.
C# API to Add Watermarks to Excel Files
In order to add watermark to Excel worksheets, we will use Aspose.Cells for .NET. It is a powerful yet easy-to-use API that lets you create, modify or convert Excel files. You can either download the API’s DLL or install it via NuGet.
PM> Install-Package Aspose.Cells
Add a Watermark to Excel Worksheet in C#
The following are the steps to add a watermark in an Excel worksheet using C#.
- Load the Excel file using Workbook class by providing its path.
- Get reference of the Worksheet to which you want to add the watermark.
- Create a watermark by adding a new Shape to the worksheet and set the its text and properties.
- Set Shape.IsLocked property to true to lock the watermark.
- Set other lock types using Shape.SetLockedProperty(ShapeLockType, bool) method.
- Save the updated Excel file using Workbook.Save(String) method.
The following code sample shows how to add a watermark to an Excel worksheet.
Output
The following is the screenshot of the Excel worksheet after adding the watermark.
Get a Free License
You can use Aspose.Cells for .NET without evaluation limitations using a temporary license.
Conclusion
In this article, you have learned how to add watermark to Excel worksheets using C#. You can easily integrate the provided code within your .NET, .NET Core, or Xamarin based applications. In addition, you can explore the documentation of Aspose.Cells for .NET. You can also post your queries on our forum.