HotXLS 文档

TXLSXHyperlinks / TXLSXHyperlink classes

Hyperlink support on a TXLSXWorksheet. Each entry anchors a single cell to an external URL. SaveAs emits a <hyperlinks> block in the worksheet plus a matching xl/worksheets/_rels/sheetN.xml.rels 文件;Open 会把关系目标解析回集合。声明于 lxHandleX

TXLSXHyperlink declaration

type
  TXLSXHyperlink = class
    constructor Create(ARow, ACol: Integer; const AUrl, ADisplay, ATooltip: WideString);
    function IsInternal: Boolean;     // True when Location is set and Url is empty
    property Row: Integer;
    property Col: Integer;
    property Url: WideString;        // External URL (mutually exclusive with Location)
    property Location: WideString;   // Internal anchor, e.g. "Sheet2!A1"
    property Display: WideString;
    property Tooltip: WideString;
  end;
      

TXLSXHyperlink members

Row, Col 1-based cell anchor coordinates
Url External URL. Written to sheetN.xml.rels with TargetMode="External"
Display Optional display text shown by Excel in place of the URL. Maps to the display attribute on <hyperlink>
Tooltip Optional tooltip shown when the user hovers the cell. Maps to the tooltip attribute on <hyperlink>

TXLSXHyperlinks declaration

type
  TXLSXHyperlinks = class
    constructor Create;
    destructor Destroy; override;
    function Add(ARow, ACol: Integer; const AUrl: WideString): Integer; overload;
    function Add(ARow, ACol: Integer; const AUrl, ADisplay: WideString): Integer; overload;
    function Add(ARow, ACol: Integer; const AUrl, ADisplay, ATooltip: WideString): Integer; overload;
    // Internal hyperlink — Location overload. No rels relationship.
    function AddInternal(ARow, ACol: Integer; const ALocation, ADisplay, ATooltip: WideString): Integer;
    function IndexOfCell(ARow, ACol: Integer): Integer;
    function FindAt(ARow, ACol: Integer): TXLSXHyperlink;
    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]: TXLSXHyperlink; default;
  end;
      

TXLSXHyperlinks members

Add(Row, Col, Url) Adds a hyperlink with just a URL. Returns the new entry index
Add(Row, Col, Url, Display) Adds a hyperlink with an explicit display text
Add(Row, Col, Url, Display, Tooltip) Adds a hyperlink with both display text and tooltip
AddInternal(Row, Col, Location, Display, Tooltip) Adds an internal anchor hyperlink — jumps to a Sheet!Cell location (e.g "Sheet2!A1") elsewhere in the workbook. No worksheet rels relationship is generated; the <hyperlink> element carries an inline location attribute. Use Worksheet.AddHyperlinkToCell(...) for the typical shortcut
IndexOfCell(Row, Col) 返回锚定在从 1 开始单元格坐标上的超链接的从 0 开始索引,若无则返回 -1 when the cell has no hyperlink
FindAt(Row, Col) Returns the hyperlink object anchored at the cell, or nil when no hyperlink is present
DeleteAt(Row, Col) Deletes the hyperlink anchored at the cell and returns True; returns False when no matching hyperlink exists
DeleteInRange(Row1, Col1, Row2, Col2) 删除锚点位于该从 1 开始的闭区间单元格范围内的所有超链接,返回删除的数量。也接受坐标颠倒的输入
Delete(Index) Deletes the hyperlink at the specified 0-based collection index
Count Number of hyperlinks on the worksheet
Items[Index] Hyperlink at the given 0-based index. Declared as the default property
Clear Removes and frees every hyperlink

示例

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

  ws.Cells.Item[1, 1].Value := 'losLab';
  ws.AddHyperlink(1, 1, 'https://www.loslab.com',
                  'losLab home', 'Open in browser');

  // Equivalent through the collection:
  ws.Hyperlinks.Add(2, 1, 'https://www.loslab.com/docs');

  if ws.Hyperlinks.FindAt(1, 1) <> nil then
    ws.Hyperlinks.DeleteInRange(1, 1, 2, 1);
end;
    

请参阅