Read the complete article on adding watermark to the Excel worksheets in Python: https://blog.aspose.com/2021/05/07/add-watermark-to-excel-worksheets-in-python/
Last active
July 7, 2021 05:32
-
-
Save aspose-com-gists/de4eea7fb32397a49be53e5c07aff4f8 to your computer and use it in GitHub Desktop.
Add Watermark to Excel Worksheets in Python
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("workbook.xlsx") | |
# Get the first default sheet | |
sheet = workbook.getWorksheets().get(0) | |
# Add watermark | |
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 | |
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("watermarked.xlsx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment