How to Add Watermark to Excel Worksheets using Java

This tutorial will demonstrate how to add watermark to Excel worksheets using Java. Excel is a popular application for data management and report creation, and it’s common to want to safeguard our data by adding watermarks to our Excel worksheets. This guide provides step-by-step instructions on how to insert watermark in XLSX using Java, including information on configuring the annotation package and a code example. Here are the detailed instructions to add watermarks into your XLSX document.

Steps to Add Watermark to Excel Worksheets using Java

  1. Install GroupDocs.Annotation for Java from the Maven repository for adding watermark in Excel worksheets
  2. Add the necessary classes into your porject for adding watermark in XLSX
  3. Instantiate the Annotator class by passing the input XLSX file path to its constructor as a parameter
  4. Create an instance of the WatermarkAnnotation class and set the properties for the watermark annotation
  5. Call the add method of the Annotator class and provide the WatermarkAnnotation object as an argument
  6. Call the save method of the Annotator class to save the output XLSX to disk

A watermark is a translucent text that appears in the background of a worksheet and is utilized to identify the document or secure its content from being duplicated. By following the aforementioned steps, you can effortlessly add watermark to Excel document in Java, without the need for any extra third-party software on your device. These instructions are compatible with Windows, macOS, Linux, and other operating systems that support Java. Below is a code sample demonstrating how to add watermarks to XLSX files.

Code to Add Watermark to Excel Worksheets using Java

import com.groupdocs.annotation.Annotator;
import com.groupdocs.annotation.licenses.License;
import com.groupdocs.annotation.models.Rectangle;
import com.groupdocs.annotation.models.annotationmodels.WatermarkAnnotation;
import java.util.Calendar;
public class AddWatermarktoExcelUsingJava {
public static void main(String[] args) {
// Set License to avoid the limitations of Annotation library
License license = new License();
license.setLicense("GroupDocs.Annotation.lic");
// Create an instance of Annotator class
Annotator annotator = new Annotator("input.xlsx");
try {
// Create an instance of WatermarkAnnotation class and set options
WatermarkAnnotation watermark = new WatermarkAnnotation();
watermark.setAngle((double) 75);
watermark.setBox(new Rectangle(200, 200, 300, 200));
watermark.setCreatedOn(Calendar.getInstance().getTime());
watermark.setText("Watermark");
watermark.setFontColor(65535);
watermark.setFontSize((double) 36);
watermark.setMessage("This is watermark annotation");
watermark.setOpacity(0.7);
watermark.setPageNumber(0);
// Add watermark annotation and save to file
annotator.add(watermark);
// Save the final XLSX to disk
annotator.save("result.xlsx");
} finally {
if (annotator != null) {
annotator.dispose();
}
}
}
}

To summarize, including watermarks in Excel spreadsheets is a valuable precaution to secure your confidential data and discourage unauthorized distribution. Using the GroupDocs.Annotation for Java package, you can easily complete the process Java create watermark in xlsx. The steps provided in this article offer a clear and concise method for inserting watermarks into your spreadsheets.

Recently, we brought out an article about adding strikeout annotation in PDF, have a look at how to add strikeout annotation in PDF using Java guide for detail.

 English