Working with worksheet backgrounds
Leave feedback
On this page
This sample iterates worksheets and prints size and byte-length details for each background image.
import groupdocs.watermark as gw
import groupdocs.watermark.contents.spreadsheet as gwc_xls
load_options = gw.SpreadsheetLoadOptions()
with gw.Watermarker("spreadsheet.xlsx", load_options) as watermarker:
content = watermarker.get_content(gwc_xls.SpreadsheetContent)
for worksheet in content.worksheets:
if worksheet.background_image is not None:
print(worksheet.background_image.width)
print(worksheet.background_image.height)
print(len(worksheet.background_image.get_bytes()))
This sample clears the background image for a selected worksheet and saves the updated workbook.
import groupdocs.watermark as gw
import groupdocs.watermark.contents.spreadsheet as gwc_xls
load_options = gw.SpreadsheetLoadOptions()
with gw.Watermarker("spreadsheet.xlsx", load_options) as watermarker:
content = watermarker.get_content(gwc_xls.SpreadsheetContent)
content.worksheets[0].background_image = None
watermarker.save("spreadsheet.xlsx")
This sample applies a centered, rotated text watermark to each worksheet’s background image.
import groupdocs.watermark as gw
import groupdocs.watermark.contents.spreadsheet as gwc_xls
import groupdocs.watermark.watermarks as gww
import groupdocs.watermark.common as gwc
load_options = gw.SpreadsheetLoadOptions()
with gw.Watermarker("spreadsheet.xlsx", load_options) as watermarker:
watermark = gww.TextWatermark("Protected image", gww.Font("Arial", 8.0))
watermark.horizontal_alignment = gwc.HorizontalAlignment.CENTER
watermark.vertical_alignment = gwc.VerticalAlignment.CENTER
watermark.rotate_angle = 45
watermark.sizing_type = gww.SizingType.SCALE_TO_PARENT_DIMENSIONS
watermark.scale_factor = 1.0
content = watermarker.get_content(gwc_xls.SpreadsheetContent)
for worksheet in content.worksheets:
if worksheet.background_image is not None:
worksheet.background_image.add(watermark)
watermarker.save("spreadsheet.xlsx")
This sample sets a chart’s background image and configures its transparency and tiling.
import groupdocs.watermark as gw
import groupdocs.watermark.contents.spreadsheet as gwc_xls
load_options = gw.SpreadsheetLoadOptions()
with gw.Watermarker("spreadsheet.xlsx", load_options) as watermarker:
content = watermarker.get_content(gwc_xls.SpreadsheetContent)
with open("test.png", "rb") as f:
content.worksheets[0].charts[0].image_fill_format.background_image = \
gwc_xls.SpreadsheetWatermarkableImage(f.read())
content.worksheets[0].charts[0].image_fill_format.transparency = 0.5
content.worksheets[0].charts[0].image_fill_format.tile_as_texture = True
watermarker.save("spreadsheet.xlsx")
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.