From: Nick Burch Date: Thu, 24 Jul 2014 21:35:47 +0000 (+0000) Subject: More internal method signature updates, for HSSF external sheets being possible range... X-Git-Tag: REL_3_11_BETA1~46 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c40ed2f75442ba34964001a3c36f66cc288883e1;p=poi.git More internal method signature updates, for HSSF external sheets being possible ranges, for #55906 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1613307 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java index 115bdd4a63..45c1612461 100644 --- a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java +++ b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java @@ -1851,13 +1851,24 @@ public final class InternalWorkbook { } /** - * Finds the sheet index for a particular external sheet number. + * Finds the (first) sheet index for a particular external sheet number. * @param externSheetNumber The external sheet number to convert * @return The index to the sheet found. */ - public int getSheetIndexFromExternSheetIndex(int externSheetNumber) + public int getFirstSheetIndexFromExternSheetIndex(int externSheetNumber) { - return linkTable.getSheetIndexFromExternSheetIndex(externSheetNumber); + return linkTable.getFirstInternalSheetIndexForExtIndex(externSheetNumber); + } + + /** + * Finds the last sheet index for a particular external sheet number, + * which may be the same as the first (except for multi-sheet references) + * @param externSheetNumber The external sheet number to convert + * @return The index to the sheet found. + */ + public int getLastSheetIndexFromExternSheetIndex(int externSheetNumber) + { + return linkTable.getLastInternalSheetIndexForExtIndex(externSheetNumber); } /** returns the extern sheet number for specific sheet number , diff --git a/src/java/org/apache/poi/hssf/model/LinkTable.java b/src/java/org/apache/poi/hssf/model/LinkTable.java index a117aef4a3..a01b287161 100644 --- a/src/java/org/apache/poi/hssf/model/LinkTable.java +++ b/src/java/org/apache/poi/hssf/model/LinkTable.java @@ -425,6 +425,9 @@ final class LinkTable { * @return -1 if the reference is to an external book */ public int getFirstInternalSheetIndexForExtIndex(int extRefIndex) { + if (extRefIndex >= _externSheetRecord.getNumOfRefs() || extRefIndex < 0) { + return -1; + } return _externSheetRecord.getFirstSheetIndexFromRefIndex(extRefIndex); } /** @@ -432,6 +435,9 @@ final class LinkTable { * @return -1 if the reference is to an external book */ public int getLastInternalSheetIndexForExtIndex(int extRefIndex) { + if (extRefIndex >= _externSheetRecord.getNumOfRefs() || extRefIndex < 0) { + return -1; + } return _externSheetRecord.getLastSheetIndexFromRefIndex(extRefIndex); } @@ -447,13 +453,6 @@ final class LinkTable { _externSheetRecord.removeSheet(sheetIdx); } - public int getSheetIndexFromExternSheetIndex(int extRefIndex) { - if (extRefIndex >= _externSheetRecord.getNumOfRefs() || extRefIndex < 0) { - return -1; - } - return _externSheetRecord.getFirstSheetIndexFromRefIndex(extRefIndex); - } - public int checkExternSheet(int sheetIndex) { int thisWbIndex = -1; // this is probably always zero for (int i=0; i<_externalBookBlocks.length; i++) { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java index 6b9ddaa7e7..84eb528d55 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java @@ -116,7 +116,8 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E return new HSSFEvaluationSheet(_uBook.getSheetAt(sheetIndex)); } public int convertFromExternSheetIndex(int externSheetIndex) { - return _iBook.getSheetIndexFromExternSheetIndex(externSheetIndex); + // TODO Update this to expose first and last sheet indexes + return _iBook.getFirstSheetIndexFromExternSheetIndex(externSheetIndex); } public ExternalSheet getExternalSheet(int externSheetIndex) { @@ -133,12 +134,17 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E return null; } - // Is it a single local sheet, or a range? - // TODO - // Look up the local sheet String sheetName = getSheetName(localSheetIndex); - sheet = new ExternalSheet(null, sheetName); + + // Is it a single local sheet, or a range? + int lastLocalSheetIndex = _iBook.getLastSheetIndexFromExternSheetIndex(externSheetIndex); + if (lastLocalSheetIndex == localSheetIndex) { + sheet = new ExternalSheet(null, sheetName); + } else { + String lastSheetName = getSheetName(lastLocalSheetIndex); + sheet = new ExternalSheetRange(null, sheetName, lastSheetName); + } } return sheet; } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 32a8391cd5..7a1479fddf 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -845,8 +845,14 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss return _sheets.size(); } + /** + * @deprecated for POI internal use only (formula parsing). This method is likely to + * be removed in future versions of POI. + */ + @Deprecated public int getSheetIndexFromExternSheetIndex(int externSheetNumber) { - return workbook.getSheetIndexFromExternSheetIndex(externSheetNumber); + // TODO - don't expose internal ugliness like externSheet indexes to the user model API + return workbook.getFirstSheetIndexFromExternSheetIndex(externSheetNumber); } private HSSFSheet[] getSheets() {