Add watermarks to spreadsheet documents

Open a spreadsheet with SpreadsheetLoadOptions and pass a spreadsheet-specific watermark option to add() to target a particular worksheet, a background, or a header/footer.

Add a watermark to a particular worksheet

Use SpreadsheetWatermarkShapeOptions and set worksheet_index to add the watermark as a shape on a specific worksheet.

from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import TextWatermark, Font, Color
from groupdocs.watermark.common import HorizontalAlignment, VerticalAlignment
from groupdocs.watermark.options.spreadsheet import (
    SpreadsheetLoadOptions, SpreadsheetWatermarkShapeOptions,
)

def add_watermark_to_worksheet():
    with Watermarker("./spreadsheet.xlsx", SpreadsheetLoadOptions()) as watermarker:
        watermark = TextWatermark("CONFIDENTIAL", Font("Arial", 19.0))
        watermark.foreground_color = Color.red
        watermark.horizontal_alignment = HorizontalAlignment.CENTER
        watermark.vertical_alignment = VerticalAlignment.CENTER

        options = SpreadsheetWatermarkShapeOptions()
        options.worksheet_index = 0
        watermarker.add(watermark, options)

        watermarker.save("./output.xlsx")

if __name__ == "__main__":
    add_watermark_to_worksheet()

spreadsheet.xlsx is the sample file used in this example. Click here to download it.

Binary file (XLSX, 48 KB)

Download full output

Other worksheet placements are available through dedicated options — SpreadsheetBackgroundWatermarkOptions (worksheet background) and SpreadsheetWatermarkHeaderFooterOptions (header/footer). Watermarker.get_content() returns a SpreadsheetContent exposing each worksheet’s shapes, charts, backgrounds, headers/footers, and attachments.

For the full set of spreadsheet content operations, see the dedicated topics:

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.