CommentsRange module

class CommentsRange.CommentsRange

Bases: XlsObject, IComment, ITextBoxShape, ITextBox, IShape

Represents a comment 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 multiple interfaces to support various aspects of comment functionality, including text box and shape behaviors.

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.

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 IsMoveWithCell: bool

Gets or sets whether the comment moves with the cell when the cell is moved.

Returns:

True if the comment moves with the cell; 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 the linked cell’s value changes, it can affect the comment’s behavior.

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 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 deletes the comment from its associated cell in the worksheet.

property ResizeBehave: ResizeBehaveType

Specifies all possible settings for how drawing object shall be resized when the rows and columns between its start and ending anchor are resized or inserted

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 angle of the comment shape in degrees.

Returns:

The rotation angle of the comment shape 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 by the specified width and height percentages.

Parameters:
  • scaleWidth (int) – The percentage to scale the width of the comment.

  • scaleHeight (int) – The percentage to scale the height of the comment.

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