Workbook-level collection of external workbook references (OOXML
externalLinks part). Each entry describes one linked .xlsx
file by its target URL and an optional list of sheet names drawn from
the cached metadata inside the link part. The collection lives on
TXLSXWorkbook.ExternalLinks.
Declared in
lxHandleX.
TXLSXExternalLink declaration
type
TXLSXExternalLink = class
constructor Create(const ATarget: WideString);
destructor Destroy; override;
property Target: WideString;
property SheetNames: TStringList;
end;
TXLSXExternalLink members
| Target |
URL of the referenced external workbook. For a
workbook in the same directory use a relative path such as
'../Reports/Sales.xlsx'; for a network location use
a full UNC or file URI. SaveAs writes this verbatim as the
relationship target and into
xl/externalLinks/externalLinkN.xml.rels. |
| SheetNames |
Optional list of sheet names inside the external
workbook. When populated, SaveAs emits
<sheetNames> children inside the
<externalBook> element so Excel can resolve
cross-workbook references without opening the linked file. Populated
automatically by Open when round-tripping an existing
workbook. Leave empty when building a link from scratch; Excel
will resolve the sheet names the next time the external file is
opened. |
TXLSXExternalLinks declaration
type
TXLSXExternalLinks = class
function Add(const ATarget: WideString): TXLSXExternalLink;
procedure Clear;
property Count: Integer;
property Items[Index: Integer]: TXLSXExternalLink; default;
end;
TXLSXExternalLinks members
| Add(Target) |
Appends a new external link with the given target
URL and returns the new TXLSXExternalLink instance.
Populate SheetNames on the returned object if known. |
| Count |
Number of external links currently in the
collection. |
| Items[Index] |
0-based access to a specific link. Declared as the
default property so Workbook.ExternalLinks[0] works
directly. |
| Clear |
Removes and frees every external link. |
SaveAs / Open behavior
When
Workbook.ExternalLinks.Count > 0, SaveAs emits:
- An
<externalReferences> block in
xl/workbook.xml with one
<externalReference r:id="rIdN"/> per link.
- A relationship entry in
xl/_rels/workbook.xml.rels pointing to
externalLinks/externalLinkN.xml.
xl/externalLinks/externalLinkN.xml containing the
<externalBook> element with the target relation
and optional <sheetNames>.
xl/externalLinks/externalLinkN.xml.rels with the
actual Target URL.
Open round-trips
Target and
SheetNames; cached cell values inside
<sheetDataSet> are not preserved by the current
release.
Example
var
wb: TXLSXWorkbook;
link: TXLSXExternalLink;
begin
wb := TXLSXWorkbook.Create;
try
link := wb.ExternalLinks.Add('../Data/Source.xlsx');
link.SheetNames.Add('Sheet1');
link.SheetNames.Add('Sheet2');
wb.Sheets.Add('Report');
wb.Sheets[0].Cells.Item[1, 1].Formula :=
'[Source.xlsx]Sheet1!$A$1';
wb.SaveAs('report.xlsx');
finally
wb.Free;
end;
end;
See also