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 ,Excel 才能渲染批注气泡;Open 会把批注 XML 读回集合。声明于 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) 返回锚定在从 1 开始单元格坐标上的批注的从 0 开始索引,若无则返回 -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) 删除锚点位于该从 1 开始的闭区间单元格范围内的所有批注,返回删除的数量。也接受坐标颠倒的输入
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

示例

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;
    

请参阅