]> source.dussan.org Git - poi.git/commitdiff
More internal method signature updates, for HSSF external sheets being possible range...
authorNick Burch <nick@apache.org>
Thu, 24 Jul 2014 21:35:47 +0000 (21:35 +0000)
committerNick Burch <nick@apache.org>
Thu, 24 Jul 2014 21:35:47 +0000 (21:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1613307 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/model/InternalWorkbook.java
src/java/org/apache/poi/hssf/model/LinkTable.java
src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java
src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java

index 115bdd4a6350a458a15dd8bca9a10d471eaa1d3c..45c16124618f1c5b5cae392a8d260f8ef16f48e3 100644 (file)
@@ -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 ,
index a117aef4a3adcb460e09902d4f73281f21943c1b..a01b287161c8b99923bd07252a7b1da10a9114f7 100644 (file)
@@ -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++) {
index 6b9ddaa7e7f633c10bada7b0efebea0b5c0ff750..84eb528d5591e30a8eb92864f62550c1ab09dd36 100644 (file)
@@ -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;
     }
index 32a8391cd50ef9d879ea87390fa2d96761042244..7a1479fddfa1b1d5060a049c07cd0cb50e4a7c31 100644 (file)
@@ -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() {