Provide XSSF-style external sheet support for areas, similar to the recent cell reference support. #56737

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1611950 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2014-07-19 19:42:07 +00:00
parent 84b50e845e
commit 86ca81d22f
4 changed files with 35 additions and 16 deletions

View File

@ -28,6 +28,7 @@ import org.apache.poi.ss.formula.eval.RefEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.formula.ptg.Area3DPxg;
import org.apache.poi.ss.formula.ptg.NameXPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.Ref3DPtg;
@ -279,17 +280,25 @@ public final class OperationEvaluationContext {
SheetRefEvaluator sre = createExternSheetRefEvaluator(rptg.getSheetName(), rptg.getExternalWorkbookNumber());
return new LazyRefEval(rptg.getRow(), rptg.getColumn(), sre);
}
public ValueEval getAreaEval(int firstRowIndex, int firstColumnIndex,
int lastRowIndex, int lastColumnIndex) {
SheetRefEvaluator sre = getRefEvaluatorForCurrentSheet();
return new LazyAreaEval(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex, sre);
}
public ValueEval getArea3DEval(int firstRowIndex, int firstColumnIndex,
int lastRowIndex, int lastColumnIndex, int extSheetIndex) {
SheetRefEvaluator sre = createExternSheetRefEvaluator(extSheetIndex);
return new LazyAreaEval(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex, sre);
}
public ValueEval getArea3DEval(Area3DPtg aptg) {
SheetRefEvaluator sre = createExternSheetRefEvaluator(aptg.getExternSheetIndex());
return new LazyAreaEval(aptg.getFirstRow(), aptg.getFirstColumn(),
aptg.getLastRow(), aptg.getLastColumn(), sre);
}
public ValueEval getArea3DEval(Area3DPxg aptg) {
SheetRefEvaluator sre = createExternSheetRefEvaluator(aptg.getSheetName(), aptg.getExternalWorkbookNumber());
return new LazyAreaEval(aptg.getFirstRow(), aptg.getFirstColumn(),
aptg.getLastRow(), aptg.getLastColumn(), sre);
}
public ValueEval getNameXEval(NameXPtg nameXPtg) {
// TODO Need HSSF and XSSF versions of these
ExternalSheet externSheet = _workbook.getExternalSheet(nameXPtg.getSheetRefIndex());
if(externSheet == null)
return new NameXEval(nameXPtg);

View File

@ -44,6 +44,7 @@ import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.apache.poi.ss.formula.functions.Function;
import org.apache.poi.ss.formula.functions.IfFunc;
import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.formula.ptg.Area3DPxg;
import org.apache.poi.ss.formula.ptg.AreaErrPtg;
import org.apache.poi.ss.formula.ptg.AreaPtg;
import org.apache.poi.ss.formula.ptg.AttrPtg;
@ -679,8 +680,10 @@ public final class WorkbookEvaluator {
return ec.getRef3DEval((Ref3DPxg)ptg);
}
if (ptg instanceof Area3DPtg) {
Area3DPtg aptg = (Area3DPtg) ptg;
return ec.getArea3DEval(aptg.getFirstRow(), aptg.getFirstColumn(), aptg.getLastRow(), aptg.getLastColumn(), aptg.getExternSheetIndex());
return ec.getArea3DEval((Area3DPtg)ptg);
}
if (ptg instanceof Area3DPxg) {
return ec.getArea3DEval((Area3DPxg)ptg);
}
if (ptg instanceof RefPtg) {
RefPtg rptg = (RefPtg) ptg;

View File

@ -25,12 +25,13 @@ import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
* Title: Area 3D Ptg - 3D reference (Sheet + Area)<P>
* Description: Defined a area in Extern Sheet. <P>
* REFERENCE: <P>
* @author Libin Roman (Vista Portal LDT. Developer)
* @author avik
* @author Jason Height (jheight at chariot dot net dot au)
* <p>Title: Area 3D Ptg - 3D reference (Sheet + Area)</p>
* <p>Description: Defined an area in Extern Sheet. </p>
* <p>REFERENCE: </p>
*
* <p>This is HSSF only, as it matches the HSSF file format way of
* referring to the sheet by an extern index. The XSSF equivalent
* is {@link Area3DPxg}
*/
public final class Area3DPtg extends AreaPtgBase implements WorkbookDependentFormula, ExternSheetReferenceToken {
public final static byte sid = 0x3b;

View File

@ -28,7 +28,7 @@ import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.formula.SheetIdentifier;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.formula.ptg.Area3DPxg;
import org.apache.poi.ss.formula.ptg.NamePtg;
import org.apache.poi.ss.formula.ptg.NameXPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
@ -150,8 +150,14 @@ public final class XSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
}
}
public Ptg get3DReferencePtg(AreaReference area, SheetIdentifier sheet) {
// TODO Implement properly
return new Area3DPtg(area, getExternalSheetIndex(sheet._sheetIdentifier.getName()));
String sheetName = sheet._sheetIdentifier.getName();
if (sheet._bookName != null) {
int bookIndex = resolveBookIndex(sheet._bookName);
return new Area3DPxg(bookIndex, sheetName, area);
} else {
return new Area3DPxg(sheetName, area);
}
}
public String resolveNameXText(NameXPtg n) {