Skip to content

xlsb: read references to sheets of other workbooks in formulas - #783

Open
Alex-ley-scrub wants to merge 1 commit into
tafia:masterfrom
Alex-ley-scrub:fix/xlsb-external-sheets
Open

Alex-ley-scrub wants to merge 1 commit into
tafia:masterfrom
Alex-ley-scrub:fix/xlsb-external-sheets

Conversation

@Alex-ley-scrub

Copy link
Copy Markdown
Contributor

Summary

Fixed issue where xlsb formula references to a sheet of another workbook were read as a sheet of this workbook.

Each entry of BrtExternSheet names a supporting workbook and a sheet index in that workbook, but only the sheet index was used, and it was looked up in this workbook's sheets. So a reference to the second sheet of another workbook was read as this workbook's second sheet, with nothing to show it was wrong.

The supporting workbooks are now read in order from BrtSupBookSrc (another workbook) and BrtSupSelf and BrtSupSame (this workbook). The sheet names of another workbook come from the BrtSupTabs record of its external link part. A reference to another workbook is written the way it's stored in xlsx, with the workbook's number: [1]Data!$A$1. Workbooks without supporting workbook records are read as before.

Formula in Excel Before After
=[ext_a.xlsx]Data!$A$1 Sheet1!$A$1 [1]Data!$A$1
=SUM([ext_a.xlsx]Second!$A$1:$A$2) SUM(Sheet2!$A$1:$A$2) SUM([1]Second!$A$1:$A$2)
=[ext_b.xlsx]Data!$A$1 Sheet1!$A$1 [2]Data!$A$1
=Sheet2!$A$1 Sheet2!$A$1 Sheet2!$A$1

Related issue

None. The same bug was reported in #717, which has since been closed. This writes the other workbook's sheet name, as xlsx does, instead of its sheet index.

Testing

tests/formula_external_sheets.xlsb was created in Excel for Mac and saved as .xlsb. Sheet1 column A refers to sheets of two other workbooks, ext_a.xlsx and ext_b.xlsx, and to its own Sheet2, and column B holds each formula as text. In this file Excel writes this workbook's BrtSupSelf after the two BrtSupBookSrc records. The same workbook saved as .xlsx stores the formulas as [1]Data!$A$1, SUM([1]Second!$A$1:$A$2) and [2]Data!$A$1.

test_xlsb_formula_external_sheets checks all four formulas. It fails without the fix.

Checklist

  • cargo test --all-features passes.
  • cargo fmt -- --check passes.
  • cargo clippy --all-targets --all-features -- -Dwarnings passes.
  • New or changed behavior is covered by a test.
  • Code and tests follow CONTRIBUTING.md.

Other information

The other workbooks aren't opened. A sheet name with spaces isn't quoted yet; #780 quotes sheet names, and I'll extend it to these references once one of the two is merged.

Fixed issue where xlsb formula references to a sheet of another workbook
were read as a sheet of this workbook.

Co-authored-by: sjvrensburg <sjansevanrensburg@gmail.com>
@jmcnamara jmcnamara added next release needs review The PR hasn't been reviewed yet. labels Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review The PR hasn't been reviewed yet. next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants