Watermarks are used to define the ownership of the copyrighted content and protect the Excel files from theft or being used illegally. In this article, you will learn how to add watermarks to Excel sheets programmatically. More precisely, the article will cover how to add watermark to Excel worksheets using Java.
Java API to Add Watermarks to Excel Worksheets
In order to add watermark to Excel files, we will use Aspose.Cells for Java. The API allows you to create, modify or convert Excel files from within the Java applications. You can either download the API’s JAR or install it using the following Maven configurations.
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://repository.aspose.com/repo/</url> </repository>
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-cells</artifactId> <version>21.6</version> </dependency>
Add Watermark to an Excel Worksheet in Java
The following are the steps to add a watermark in an Excel worksheet using Java.
- First, 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.setLocked(boolean) property to true to lock the watermark.
- Set other lock types using Shape.setLockedProperty(ShapeLockType, boolean) method.
- Finally, save the updated Excel file using Workbook.save(String) method.
The following code sample shows how to add a watermark to an Excel worksheet.
The following is the screenshot of the Excel worksheet after adding the watermark.
Get a Free License
You can use Aspose.Cells for Java without evaluation limitations using a temporary license.
In this article, you have learned how to add watermark to Excel worksheets using Java. The provided code sample can easily be integrated into the Java applications. You can also explore other features of Aspose.Cells for Java using the documentation. In case you would have any queries, you can post on our forum.