linexcel.external¶
linexcel.external ¶
Workbooks a file depends on, and how far linexcel can follow them.
A formula reading '[1]Annual'!B4 names another workbook. The file itself
says which one: xl/externalLinks/externalLink1.xml and its relationship
carry the path Excel last saw it at, and, when Excel saved the link, a cache
of the values that were read. Neither is visible to the calculation engine, so
without this module such a cell is a grey "external reference" node and every
formula above it loses its value.
Three levels of answer, in the order they are tried:
- Named. The path and file name are always readable, so the report can say
which workbook a cell depends on instead of showing
[1]. - Cached. Most files carry the values Excel last read across the link. They are what the user saw on screen, and they cost nothing to read.
- Resolved. Given a folder of the referenced files, the workbook is opened
and read for real, which is also where VBA lives when the code sits in an
add-in (
.xlam,.xla) rather than in the workbook itself.
Level 3 is opt-in: analyze(..., refs_dir=...). Nothing is read from disk
unless a caller names the folder.
ExternalBook
dataclass
¶
One workbook the analyzed file reads from.
Source code in src/linexcel/external.py
value ¶
(value, source) for one cell of this workbook.
The file on disk wins over the cache: the cache is what Excel read the last time it opened the link, which may be older than the workbook a caller has just pointed linexcel at.
Source code in src/linexcel/external.py
ExternalRef
dataclass
¶
An external reference as written in a formula.
Source code in src/linexcel/external.py
parse_external_refs ¶
Every external reference a formula makes, in order of appearance.
Source code in src/linexcel/external.py
read_external_links ¶
The workbooks a file declares a link to, keyed by [N] index.
The index is the position in <externalReferences> in xl/workbook.xml,
not the number in the part name, which only coincides most of the time.
Source code in src/linexcel/external.py
find_workbooks ¶
Workbook files in folder, keyed by lowercased file name.
The first match wins, and the shallowest one is seen first, so a file next to the workbook takes precedence over a copy buried in a subfolder.
Source code in src/linexcel/external.py
resolve_books ¶
resolve_books(
books: dict[str, ExternalBook],
folder: Path,
warnings: list[str],
*,
max_dense_cells: int | None = None,
) -> None
Read every declared workbook that the folder actually holds.
Source code in src/linexcel/external.py
read_workbook_values ¶
read_workbook_values(
path: Path, *, max_dense_cells: int | None = None
) -> dict[tuple[str, int, int], Any]
Every value of a workbook, by (sheet, row, col).
Only values: a referenced workbook is read for what the formulas above it need, and Excel itself stores nothing but values across a link.
Source code in src/linexcel/external.py
macro_files ¶
Files in folder that can carry a VBA project.