Read the complete article on adding watermark to Excel worksheets in Java: https://blog.aspose.com/2021/06/07/add-watermark-to-excel-worksheets-using-java/
Last active
July 7, 2021 05:00
-
-
Save aspose-com-gists/7ba1fc8dc4c8cf93eadb60dfba54ce0b to your computer and use it in GitHub Desktop.
Add Watermark to Excel Worksheet in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the Excel file | |
Workbook workbook = new Workbook("Excel.xlsx"); | |
// Get the first default sheet | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Add watermark | |
Shape wordart = sheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1, "CONFIDENTIAL", | |
"Arial Black", 50, false, true, 18, 8, 1, 1, 130, 800); | |
// Get the fill format of the word art | |
FillFormat wordArtFormat = wordart.getFill(); | |
// Set the color | |
wordArtFormat.setOneColorGradient(Color.getRed(), 0.2, GradientStyleType.HORIZONTAL, 2); | |
// Set the transparency | |
wordArtFormat.setTransparency(0.9); | |
// Make the line invisible | |
wordart.setHasLine(false); | |
// Lock shape aspects | |
wordart.setLocked(true); | |
wordart.setLockedProperty(ShapeLockType.SELECTION, true); | |
wordart.setLockedProperty(ShapeLockType.SHAPE_TYPE, true); | |
wordart.setLockedProperty(ShapeLockType.MOVE, true); | |
wordart.setLockedProperty(ShapeLockType.RESIZE, true); | |
wordart.setLockedProperty(ShapeLockType.TEXT, true); | |
// Save the watermarked Excel file | |
workbook.save("output.xlsx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment