Skip to content

fix: external link indices are quoted where Excel writes them bare - #55

Open
gthb wants to merge 2 commits into
borgar:masterfrom
gthb:dont-quote-external-link-index
Open

fix: external link indices are quoted where Excel writes them bare#55
gthb wants to merge 2 commits into
borgar:masterfrom
gthb:dont-quote-external-link-index

Conversation

@gthb

@gthb gthb commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What

Stop quoting a reference prefix whose workbook part is an external link index. Excel writes it bare; Fx quoted it:

Excel   SUM([1]Sheet1!A1)
Fx      SUM('[1]Sheet1'!A1)

Nothing breaks (Excel accepts the quoted form and strips it on the next save), but [n] is the only external reference form a stored workbook uses, so every such prefix Fx rewrites gains quotes Excel then removes: noise in stored formula text, and diff noise across a round trip.

Cause

needQuotes quotes any scope starting with a digit, to keep it from reading as a numeric literal. Sound for a bare name, but a link index is delimited by its brackets and so cannot be read as a number.

Fix

needQuotes takes a bracketed flag and skips the digit-leading rule for an all-digit scope when it is set; both prefix variants pass it.

The exemption is the index alone. A digit-leading workbook name ([1040.xlsx]) stays quoted, as does any digit-leading sheet name, and a sheet name that needs quotes for its own reasons still quotes the whole prefix with the brackets inside the quotes: '[1]Sheet 1'!A1. Translation follows the same rule, so the right side of a range operator, which Excel always quotes, stays '[1]Sheet1'!$B$2.

Excel behaviour

Entered against an open external workbook, then read back from the stored <f>:

entered formula bar stored <f>
=SUM([ExtSrc3.xlsx]Alpha!A1) unchanged SUM([1]Alpha!A1)
=SUM('[ExtSrc3.xlsx]Alpha'!A1) =SUM([ExtSrc3.xlsx]Alpha!A1) SUM([1]Alpha!A1)

Normalization runs both ways (Excel adds missing quotes and strips redundant ones), so no hand-written form survives a save unchanged. The one form that is not merely redundant is the partly quoted prefix: [1]'Alpha'!A1, with the bracket outside the quotes, makes Excel offer to repair the file and drop the cell, while '[1]Alpha'!A1 opens fine. Hence quoting the brackets along with the rest.

Excel writes the workbook part of an external reference bare when it is a
link index — SUM([1]Sheet1!A1) — but fx quoted it, producing
SUM('[1]Sheet1'!A1).

needQuotes quotes any scope starting with a digit, to keep it from being
read as a numeric literal. That holds for a bare name, but an external
link index is delimited by its brackets and so cannot be read as a
number. needQuotes now takes a `bracketed` flag, and skips the
digit-leading rule for an all-digit scope when it is set.

The exemption is the index alone. A digit-leading workbook *name*
([1040.xlsx]) is still quoted, so is any digit-leading sheet name, and a
sheet name that needs quotes for its own reasons still quotes the whole
prefix, brackets included.

Nothing was broken by the old spelling — Excel accepts it and normalizes
it away on the next save. The cost was churn: [n] is the commonest
external reference form there is, so every such prefix fx rewrote gained
quotes Excel then removed, as noise in stored formula text and as diff
noise across a round trip.
@gthb
gthb marked this pull request as ready for review August 5, 2026 17:20
The bare index is a second observable change on this path: the left side
of a range operator now keeps it bare, while the right side still quotes
the whole prefix with the brackets inside the quotes — the spelling Excel
accepts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant