Docs HotXLS

TXLSXComments / TXLSXComment classes

Cell-comment support on a TXLSXWorksheet. Each entry attaches an author plus a free-text body to a cell. SaveAs emits xl/commentsN.xml with a deduplicated author list and a companion xl/drawings/vmlDrawingN.vml so Excel can render the comment balloons; Open reads the comments XML back into the collection. Declared in lxHandleX

TXLSXComment declaration

type
  TXLSXComment = class
    constructor Create(ARow, ACol: Integer; const AAuthor, AText: WideString);
    property Row: Integer;
    property Col: Integer;
    property Author: WideString;
    property Text: WideString;
  end;
      

TXLSXComment members

Row, Col 1-based cell anchor coordinates
Author Comment author name. Distinct names are written once into the workbook-level <authors> list and referenced by authorId
Text Comment body text. Written as a single <text><r><t> run on SaveAs and flattened from one or more runs on Open

TXLSXComments declaration

type
  TXLSXComments = class
    constructor Create;
    destructor Destroy; override;
    function Add(ARow, ACol: Integer; const AText: WideString): Integer; overload;
    function Add(ARow, ACol: Integer; const AText, AAuthor: WideString): Integer; overload;
    function IndexOfCell(ARow, ACol: Integer): Integer;
    function FindAt(ARow, ACol: Integer): TXLSXComment;
    function DeleteAt(ARow, ACol: Integer): Boolean;
    function DeleteInRange(ARow1, ACol1, ARow2, ACol2: Integer): Integer;
    procedure Delete(Index: Integer);
    procedure Clear;
    property Count: Integer;
    property Items[Index: Integer]: TXLSXComment; default;
  end;
      

TXLSXComments members

Add(Row, Col, Text) Adds an unsigned comment (empty author). Returns the new entry index
Add(Row, Col, Text, Author) Adds a comment with an explicit author name
IndexOfCell(Row, Col) Returns the 0-based index of the comment anchored at the 1-based cell coordinate, or -1 when the cell has no comment
FindAt(Row, Col) Returns the comment object anchored at the cell, or nil when no comment is present
DeleteAt(Row, Col) Deletes the comment anchored at the cell and returns True; returns False when no matching comment exists
DeleteInRange(Row1, Col1, Row2, Col2) Deletes every comment whose anchor is inside the inclusive 1-based cell range and returns the number removed. Reversed coordinates are accepted
Delete(Index) Deletes the comment at the specified 0-based collection index
Count Number of comments on the worksheet
Items[Index] Comment at the given 0-based index. Declared as the default property
Clear Removes and frees every comment

Exemple

var
  ws: TXLSXWorksheet;
begin
  ws := Workbook.Sheets.Add('Reviews');

  ws.Cells.Item[1, 1].Value := 'Q1 revenue';
  ws.AddComment(1, 1, 'Numbers still pending review', 'Kevin');

  // Equivalent through the collection:
  ws.Comments.Add(2, 1, 'Auto-generated draft');

  if ws.Comments.IndexOfCell(1, 1) >= 0 then
    ws.Comments.DeleteAt(1, 1);
end;
    

Voir aussi