public ExternalName getExternalName(String nameName, String sheetName, int externalWorkbookNumber) {
if (externalWorkbookNumber > 0) {
// External reference - reference is 1 based, link table is 0 based
int linkNumber = externalWorkbookNumber - 1;
ExternalLinksTable linkTable = _uBook.getExternalLinksTable().get(linkNumber);
for (org.apache.poi.ss.usermodel.Name name : linkTable.getDefinedNames()) {
if (name.getNameName().equals(nameName)) {
// HSSF returns one sheet higher than normal, and various bits
// of the code assume that. So, make us match that behaviour!
int nameSheetIndex = name.getSheetIndex() + 1;
// TODO Return a more specialised form of this, see bug #56752
// Should include the cached values, for in case that book isn't available
// Should support XSSF stuff lookups
return new ExternalName(nameName, -1, nameSheetIndex);
}
}
throw new IllegalArgumentException("Name '"+nameName+"' not found in " +
"reference to " + linkTable.getLinkedFileName());
} else {
// Internal reference
int nameIdx = _uBook.getNameIndex(nameName);
return new ExternalName(nameName, nameIdx, 0); // TODO Is this right?
}