Shapes in spreadsheet document

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Watermark MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-watermark -- dnx GroupDocs.Watermark.Mcp --yes
Folders, licensing and more →

Watermarker.get_content() returns a SpreadsheetContent whose worksheets each expose a shapes collection (along with charts, attachments, and background_image). You can iterate the shapes to read their properties, modify them, or remove them.

Extract information about shapes

from groupdocs.watermark import Watermarker
from groupdocs.watermark.options.spreadsheet import SpreadsheetLoadOptions

def extract_shapes():
    with Watermarker("./spreadsheet.xlsx", SpreadsheetLoadOptions()) as watermarker:
        content = watermarker.get_content()
        for i, worksheet in enumerate(content.worksheets):
            print(f"Worksheet {i}: shapes={len(worksheet.shapes)}")
            for shape in worksheet.shapes:
                text = (shape.text or "").strip()
                print(f"  shape text={text!r} size={round(shape.width)}x{round(shape.height)} "
                      f"word_art={shape.is_word_art}")

if __name__ == "__main__":
    extract_shapes()

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

Worksheet 0: shapes=3
  shape text='CONFIDENTIAL' size=315x52 word_art=True
  shape text='Rates valid until 31 December 2026. Prices exclude VAT.' size=270x30 word_art=False
  shape text='' size=135x40 word_art=False
Worksheet 1: shapes=0

Download full output

Each shape exposes text, image, name, alternative_text, x, y, width, height, rotate_angle, and is_word_art.

Remove and modify shapes

The shapes collection supports remove_at(index) and remove(shape). Iterate in reverse when removing by index:

from groupdocs.watermark import Watermarker
from groupdocs.watermark.options.spreadsheet import SpreadsheetLoadOptions

def remove_and_modify_shapes():
    with Watermarker("./spreadsheet.xlsx", SpreadsheetLoadOptions()) as watermarker:
        content = watermarker.get_content()
        for worksheet in content.worksheets:
            for i in range(len(worksheet.shapes) - 1, -1, -1):
                if worksheet.shapes[i].text == "CONFIDENTIAL":
                    worksheet.shapes.remove_at(i)
        watermarker.save("./output.xlsx")

if __name__ == "__main__":
    remove_and_modify_shapes()

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

Binary file (XLSX, 149 KB)

Download full output

You can replace a shape’s text by assigning to shape.text, replace its image by assigning a SpreadsheetWatermarkableImage to shape.image, set a hyperlink via shape.hyperlink, and modify its position and size.