HotXLS 參考頁面,介紹 TXLSXComments / TXLSXComment 類別,涵蓋 Delphi 和 C++Builder 的 Excel 自動化、XLS/XLSX 活頁簿 API、工作表功能及 Pascal 用法

,並搭配

,使 Excel 能呈現批註氣泡;Open 將批註 XML 讀回集合。宣告於 TXLSXComment 宣告. 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

1-基於 儲存格 anchor coordinates

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;
      

清單,並以 authorId 參照

Row, Col清單,並以 authorId 參照
AuthorComment author name. Distinct names are written once into the workbook-level <authors> list and referenced by authorId
TextTXLSXComments 宣告 <text><r><t> run on SaveAs and flattened from one or more runs on Open

TXLSXComments 成員

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;
      

加入未簽名註解(空白作者)。回傳新的項目索引

Add(Row, Col, Text)Adds an unsigned comment (empty author). 傳回 the new entry index
Add(Row, Col, Text, Author)加入含明確作者名稱的註解
IndexOfCell(Row, Col)傳回 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)回傳錨定於該儲存格的註解物件;若沒有註解則回傳 nil nil 刪除錨定於該儲存格的註解並回傳 True;若找不到對應註解則回傳 False
DeleteAt(Row, Col)刪除錨定於該儲存格的註解並回傳 True;若找不到對應註解則回傳 False TrueDeleteInRange(Row1, Col1, Row2, Col2) 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指定 0 起始索引的註解。宣告為預設屬性
Items[Index]Comment at the given 0-based index. Declared as the default property
Clear移除並釋放所有註解

另請參閱

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;
    

TXLSXWorksheet