Documentazione 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 file; Open risolve le destinazioni delle relationship nella raccolta. Dichiarata in 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. Restituisce 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 e 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. Usa Worksheet.AddHyperlinkToCell(...) for the typical shortcut
IndexOfCell(Row, Col) Restituisce the 0-based index of the hyperlink anchored at the 1-based cell coordinate, o -1 when the cell has no hyperlink
FindAt(Row, Col) Restituisce the hyperlink object anchored at the cell, o nil when no hyperlink is present
DeleteAt(Row, Col) Deletes the hyperlink anchored at the cell e returns True; returns False when no matching hyperlink exists
DeleteInRange(Row1, Col1, Row2, Col2) Deletes every hyperlink whose anchor is inside the inclusive 1-based cell range e returns the number removed. Reversed coordinates are accepted
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 proprietà
Clear Removes e frees every hyperlink

Esempio

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;
    

Vedere also