fix: external link indices are quoted where Excel writes them bare - #55
Open
gthb wants to merge 2 commits into
Open
fix: external link indices are quoted where Excel writes them bare#55gthb wants to merge 2 commits into
gthb wants to merge 2 commits into
Conversation
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Stop quoting a reference prefix whose workbook part is an external link index. Excel writes it bare; Fx quoted it:
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
needQuotesquotes 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
needQuotestakes abracketedflag 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>:<f>=SUM([ExtSrc3.xlsx]Alpha!A1)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'!A1opens fine. Hence quoting the brackets along with the rest.