Bug 63554 - XSSFName.getSheetName() returns wrong sheet
Summary: XSSFName.getSheetName() returns wrong sheet
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.17-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2019-07-08 13:41 UTC by babochenko.denis
Modified: 2019-11-17 12:38 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description babochenko.denis 2019-07-08 13:41:59 UTC
(unfortunately, I cannot attach an example of document for security reasons)
(might be related to https://bz.apache.org/bugzilla/show_bug.cgi?id=45430, BUT is reproduced in POI 3.15)

Let's say I have to parse a document with named cells and that I have no
influence on the design/structure of a document itself.

I have to extract a named cell from Workbook. Let's say xl/workbook.xml has following entries:

<definedName name="someName" localSheetId="20">someSheet!$B$21</definedName>
<definedName name="someName" localSheetId="6">someSheet!$B$21</definedName>
<definedName name="someName" localSheetId="4">someSheet!$B$21</definedName>
<definedName name="someName">someSheet!$B$21</definedName>

'someSheet' has idx == 15.

XSSFName name = Workbook.getName("someName")
name.getSheetIndex() uses localSheetId and returns "20", which refers to a wrong sheet.

Current workaround:
new CellReference(name.getRefersToFormula()).getSheetIndex() returns expected index (15)