}
/**
- * 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 ,
* @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);
}
/**
* @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);
}
_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++) {
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) {
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;
}
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() {