Repository navigation
Conversation
…vots and the Name Box
Sheet names were quoted in three places with three rules (the formula
printer, engine::pivot::quote_sheet, ADDRESS) and unquoted in seven (two
split_sheet copies in the engine, xlsx pivot and array-formula readers,
chart resolve, engine cmd/pivot, the Name Box). gridcraft_core::addr now
holds sheet_needs_quotes, quote_sheet, unquote_sheet and split_sheet, and
every copy uses them.
The rule, observed in Excel 365 (typing ='name'!A1 and reading .Formula
back, and ADDRESS(1,1,1,TRUE,name)): a name is quoted when it reads as an
A1 cell on the sheet (A1, XFD1, AB1048576; not XFE1), an R1C1 reference in
any case (R, C, RC, R1, C1, R1C, RC1, R1C1), a boolean, starts with a digit
or a dot, or holds anything but letters, digits, _ and dot. ADDRESS leaves
TRUE and FALSE bare.
Fixes:
- A formula into a sheet named .x was saved as .x!A1, and Excel 365 can't
open such a file, not even with repair.
- A PivotTable made from the current region of a sheet named A1 reported
its source as A1!$A$1:$B$3 (the engine's copy lacked the cell check).
- ADDRESS(1,1,1,TRUE,"A1") gave A1!$A$1; Excel gives 'A1'!$A$1. The same
for R1C1-like names and a leading dot.
- The Name Box never showed a name on sheet Bob's: it compared Bob''s with
Bob's.
- Go To built '{name}'! by hand without doubling apostrophes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SAgnkqJiy3v24Hp25dQLRj
Author
|
Closing this pull request. The problem, Excel's measurements and a fix approach are now in #1458. |
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.
Summary
Sheet names in references were quoted and unquoted in about eight places, with three different quoting rules. This PR moves the rule into one place,
gridcraft_core::addr(sheet_needs_quotes,quote_sheet,unquote_sheet,split_sheet), uses it everywhere, and makes it match Excel 365. It fixes:.was saved as.x!A1, and Excel 365 can't open that file, not even with repair.A1!$A$1:$B$3.Observed
Excel 365's rule, from typing
='name'!A1and reading.Formulaback, and fromADDRESS(1,1,1,TRUE,name):A1,XFD1,AB1048576XFE1,AB1048577(off the sheet)R,C,RC,R1,C1,R1C,RC1,R1C1,r2c3.xTRUE,falseÄrger,日本,Σ,Sheet.1,_x,A1AEffects in GridCraft (main):
='.x'!A1was saved as<f>.x!A1</f>. Excel 365 refuses to open the file, and the repair option fails too.R1C1!A1andRC!A1happen to be accepted by Excel.insert.pivotTablefrom the current region of a sheet namedA1:pivot.listgave the sourceA1!$A$1:$B$3. The text comes from the engine's ownpivot::quote_sheet, which lacks the cell-name check.ADDRESS(1,1,1,TRUE,"A1")gaveA1!$A$1; Excel gives'A1'!$A$1.='Bob''s'!$A$1:$B$2never showed in the Name Box: it comparedBob''swithBob's.Cause
needs_quoteschecked cells and booleans but not R1C1 tokens or a leading..engine::pivot::quote_sheetchecked neither cells nor R1C1 tokens. ADDRESS's own copy didn't check cells or R1C1 tokens either.trim_matches('\'').replace("''","'")appeared inengine/src/cmd/mod.rs,engine/src/pivot.rs(twice),xlsx/src/pivot.rsandxlsx/src/array_formula.rs;strip_prefix/strip_suffixinchart/src/resolve.rsandengine/src/cmd/pivot.rs. The Name Box had a seventh that didn't unescape''.'{name}'!…by hand, without doubling apostrophes.Fix
gridcraft_core::addr(L0, reachable from every crate):sheet_needs_quotesandquote_sheetfollow the table above. That means cell-like names within the sheet's bounds, R1C1 tokens in any case, booleans, a leading digit or., and any character other than letters, digits,_and..unquote_sheetandsplit_sheettake the sheet part apart (split at the last!,''read as').quote_sheetandneeds_quotesfrom core;gridcraft_formula::quote_sheetkeeps working.quote_sheet/split_sheetandcmd::split_sheetnow come from core. Solver, Go To, xlsx pivot/array-formula, chart resolve and the Name Box use the same helpers.sheet_needs_quotesand leavesTRUE/FALSEbare, as Excel's ADDRESS does.Testing
sheet_names_are_quoted_like_excel, every row of the table above.A1,R1C1,RC,.x,XFE1andTRUE.sheet_names_are_quoted_by_excels_rule_everywhere. A pivot made from the current region of sheetA1reports'A1'!$A$1:$B$3, and='.x'!A1+'R1C1'!A1keeps its quotes.tests/name_box.rs, a name on sheetBob'sshows in the Name Box.cargo fmt --all -- --check;cargo clippyfor core, formula, functions, xlsx, chart, engine and ui-egui with-D warnings;cargo testfor the same crates.Overlap: #829 also rewrites
needs_quotesincrates/formula/src/printer.rs([1]Sheet/[Book.xlsx]Sheetprefixes, with a localsheet_needs_quotes). Whichever lands second should make #829's wrapper callgridcraft_core::addr::sheet_needs_quotes.🤖 Generated with Claude Code
https://claude.ai/code/session_01SAgnkqJiy3v24Hp25dQLRj