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
This commit is contained in:
Nick Burch 2014-07-24 21:35:47 +00:00
parent 7f6ba5513c
commit e27a6e5466
4 changed files with 38 additions and 16 deletions

View 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 ,

View 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++) {

View 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;
}

View 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() {