Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active July 7, 2021 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/de4eea7fb32397a49be53e5c07aff4f8 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/de4eea7fb32397a49be53e5c07aff4f8 to your computer and use it in GitHub Desktop.
Add Watermark to Excel Worksheets in Python
# 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