ExcelCommentObject module

class ExcelCommentObject.ExcelCommentObject

Bases: SpireObject, IComment

Represents a comment object in an Excel worksheet.

This class encapsulates the functionality of a comment attached to a cell in an Excel worksheet. It provides properties and methods to manage comment visibility, text content, formatting, and positioning. The class implements the IComment interface to support standard comment operations.

property AlternativeText: str

Gets or sets the alternative text description for the comment shape.

Alternative text is used for accessibility purposes and appears when the comment is hovered over or when the comment cannot be displayed.

Returns:

The alternative text for the comment shape.

Return type:

str

property Author: str

Gets or sets the author of the comment.

Returns:

The name of the author who created the comment.

Return type:

str

property AutoSize: bool

Gets or sets whether the comment is automatically sized to fit its content.

When set to True, the comment will automatically resize to fit the text within its boundaries.

Returns:

True if the comment is automatically sized; otherwise, False.

Return type:

bool

property Column: int

Gets the column index of the cell that contains the comment.

Returns:

The zero-based column index.

Return type:

int

property Fill: IShapeFill

Gets the fill formatting for the comment shape.

The fill formatting includes properties such as fill color, pattern, and gradient.

Returns:

The fill formatting object for the comment shape.

Return type:

IShapeFill

property Glow: IGlow

Gets the glow effect formatting for the comment shape.

The glow effect adds a colored, blurred outline around the comment.

Returns:

The glow effect formatting object for the comment shape.

Return type:

IGlow

property HAlignment: CommentHAlignType

Gets or sets the horizontal alignment of text in the comment.

Returns:

An enumeration value representing the horizontal alignment type.

Return type:

CommentHAlignType

property Height: int

Gets or sets the height of the comment shape in points.

Returns:

The height of the comment shape in points.

Return type:

int

property HtmlString: str

Gets or sets the HTML string which contains data and some formatting in this comment.

Returns:

The HTML representation of the comment content with formatting.

Return type:

str

property ID: int

Gets the unique identifier for the comment shape.

Returns:

The unique identifier for the comment shape.

Return type:

int

property IsLockAspectRatio: bool

Gets or sets whether the aspect ratio of the comment shape is locked.

When the aspect ratio is locked, the width and height of the comment shape maintain their proportions when the shape is resized.

Returns:

True if the aspect ratio is locked; otherwise, False.

Return type:

bool

property IsLocked: bool

Gets or sets whether the comment shape is locked.

When a comment shape is locked, it cannot be modified when the worksheet is protected.

Returns:

True if the comment shape is locked; otherwise, False.

Return type:

bool

property IsPrintable: bool

Gets or sets whether the comment shape is printed when the worksheet is printed.

Returns:

True if the comment shape is printed; otherwise, False.

Return type:

bool

property IsSmartArt: bool

Gets whether the comment is part of a SmartArt object.

Returns:

True if the comment is part of a SmartArt object; otherwise, False.

Return type:

bool

property IsTextLocked: bool

Gets or sets whether the text in the comment is locked.

When the text is locked, it cannot be edited when the worksheet is protected.

Returns:

True if the text in the comment is locked; otherwise, False.

Return type:

bool

property IsVisible: bool

Gets or sets whether the comment is visible.

Returns:

True if the comment is visible; otherwise, False.

Return type:

bool

property Left: int

Gets or sets the horizontal position of the comment shape in points.

Returns:

The horizontal position of the comment shape in points, measured from the left edge.

Return type:

int

property Line: IShapeLineFormat

Gets the line formatting for the comment shape border.

The line formatting includes properties such as line color, style, and weight.

Returns:

The line formatting object for the comment shape border.

Return type:

IShapeLineFormat

property LinkedCell: IXLSRange

Gets or sets the cell range that is linked to the comment.

When a cell range is linked to a comment, changes to the linked cell can affect the comment’s behavior or appearance.

Returns:

The cell range that is linked to the comment.

Return type:

IXLSRange

property Name: str

Gets or sets the name of the comment shape.

Returns:

The name of the comment shape.

Return type:

str

property OnAction: str

Gets or sets the name of the macro to run when the comment is clicked.

Returns:

The name of the macro to run when the comment is clicked.

Return type:

str

property Parent: SpireObject

Gets the parent object of the comment.

Returns:

The parent object that contains this comment.

Return type:

SpireObject

property Reflection: IReflectionEffect

Gets the reflection effect formatting for the comment shape.

The reflection effect adds a reflection of the comment below it.

Returns:

The reflection effect formatting object for the comment shape.

Return type:

IReflectionEffect

Remove()

Removes the comment from the worksheet.

This method permanently deletes the comment from the worksheet. After calling this method, the comment object is no longer valid.

property ResizeBehave: ResizeBehaveType

Gets or sets how the comment shape resizes when rows and columns are resized.

This property specifies how the drawing object shall be resized when the rows and columns between its start and ending anchor are resized or inserted.

Returns:

An enumeration value representing the resize behavior type.

Return type:

ResizeBehaveType

property RichText: IRichTextString

Gets the rich text formatting of the comment.

Returns:

An object representing the rich text formatting applied to the comment text.

Return type:

IRichTextString

property Rotation: int

Gets or sets the rotation of the comment shape, in degrees.

This property controls the angle of rotation for the comment shape. Positive values rotate the shape clockwise, while negative values rotate it counterclockwise.

Returns:

The rotation angle in degrees.

Return type:

int

property Row: int

Gets the row index of the cell that contains the comment.

Returns:

The zero-based row index.

Return type:

int

Scale(scaleWidth: int, scaleHeight: int)

Scales the comment shape by the specified percentages.

This method resizes the comment shape according to the specified width and height scaling percentages.

Parameters:
  • scaleWidth (int) – The percentage to scale the width (100 = original size).

  • scaleHeight (int) – The percentage to scale the height (100 = original size).

SetCommentLocation(isMoveWithCell: bool, isSizeWithCell: bool)

Sets the location behavior of the comment when cells are moved or resized.

Parameters:
  • isMoveWithCell (bool) – True to move the comment when the cell is moved; otherwise, False.

  • isSizeWithCell (bool) – True to resize the comment when the cell is resized; otherwise, False.

property Shadow: IShadow

Gets the shadow effect formatting for the comment shape.

The shadow effect adds a shadow behind the comment.

Returns:

The shadow effect formatting object for the comment shape.

Return type:

IShadow

property ShapeType: ExcelShapeType

Gets or sets the shape type of the comment.

Returns:

An enumeration value representing the shape type of the comment.

Return type:

ExcelShapeType

property Text: str

Gets or sets the text content of the comment.

Returns:

The text content of the comment.

Return type:

str

property TextFrame: ITextFrame

Gets the text frame object for the comment shape.

The text frame contains properties related to the text display within the comment.

Returns:

The text frame object for the comment shape.

Return type:

ITextFrame

property TextRotation: TextRotationType

Gets or sets the rotation type of the text in the comment.

Returns:

An enumeration value representing the text rotation type.

Return type:

TextRotationType

property ThreeD: IFormat3D

Gets the 3D formatting for the comment shape.

The 3D formatting includes properties such as depth, contour, and surface.

Returns:

The 3D formatting object for the comment shape.

Return type:

IFormat3D

property Top: int

Gets or sets the vertical position of the comment shape in points.

Returns:

The vertical position of the comment shape in points, measured from the top edge.

Return type:

int

property VAlignment: CommentVAlignType

Gets or sets the vertical alignment of text in the comment.

Returns:

An enumeration value representing the vertical alignment type.

Return type:

CommentVAlignType

property Visible: bool

Gets or sets whether the comment shape is visible in the worksheet.

Returns:

True if the comment shape is visible; otherwise, False.

Return type:

bool

property Width: int

Gets or sets the width of the comment shape in points.

Returns:

The width of the comment shape in points.

Return type:

int