Repository navigation
xls, xlsb: quote sheet names in formulas - #780
Alex-ley-scrub wants to merge 1 commit into
Conversation
|
One reason I passed on #713 the first time around was that the quote checking didn't look complete. But I didn't get around to pointing that out. You seem to have done a better job. I also tackled the same problem in https://github.com/jmcnamara/rust_xlsxwriter/blob/main/src/utility.rs#L720-L827 It also has a largish test case that I generated from real Excel files: https://github.com/jmcnamara/rust_xlsxwriter/blob/main/src/utility/tests.rs#L151 |
|
Thanks, that's a much more complete set of rules. I've switched to the rules from |
@Alex-ley-scrub Thanks for pointing that out. I've added it to |
Fixed issue where xls and xlsb formulas wrote sheet names without quotes, so a reference to `'My Sheet'!A1` was read as `My Sheet!A1`. With sheets named `Q3 SALES` and `SALES`, a reference to the first read as a reference to the second. Sheet names are now quoted with the rules from `quote_sheet_name()` in rust_xlsxwriter, and also when the name is `TRUE` or `FALSE`, which Excel quotes too. An apostrophe in a quoted name is doubled. Co-authored-by: sjvrensburg <sjansevanrensburg@gmail.com>
b5830e9 to
bcd1947
Compare
Summary
Fixed issue where xls and xlsb formulas wrote sheet names without quotes, so a reference to
'My Sheet'!A1was read asMy Sheet!A1. With sheets namedQ3 SALESandSALES, a reference to the first read as a reference to the second.A sheet name is now quoted when Excel would quote it, by a new
quote_sheet_name()inutils.rs. Each reader quotes the names once, in the list of sheet names that its formulas use. Excel quotes a name that:_, such as'2024';_or., such as'My Sheet','a-b'or'€uro';TRUEorFALSE;'A1'or'XFD1'but notXFE1, which is past the last column;'R','C','RC'or'R2C3'.An apostrophe in a quoted name is doubled, as in
'Bob''s'.The rules come from the formula text Excel for Mac wrote for each name. Excel's R1C1 check has some quirks: it quotes
R1xbut notR1.orR0. The new function quotes all names that start withR,CorRCfollowed by a digit, so it quotes a few names that Excel doesn't. A quoted name is still a valid reference.Related issue
None. The same bug was reported in #713, which has since been closed. This follows its approach, and also quotes
R2C3,RCandTRUEand leavesXFE1unquoted, as Excel does.Testing
tests/formula_sheet_names.xlsbandtests/formula_sheet_names.xlswere created in Excel for Mac. They have 20 sheets named to cover each rule above, and Sheet1 column B refers to each one. Column A holds each sheet name, and column C holds the formula as Excel writes it, which the tests expect.test_xlsb_formula_sheet_namesandtest_xls_formula_sheet_namescheck all 20 formulas. They fail without the fix.Checklist
cargo test --all-featurespasses.cargo fmt -- --checkpasses.cargo clippy --all-targets --all-features -- -Dwarningspasses.Other information
In xlsb, defined names read their references through the same sheet list, so they're quoted too. The xls defined names are built separately and aren't changed here.