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 ae72a675ca
commit 5458a295aa
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.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction; import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.apache.poi.ss.formula.ptg.Area3DPtg; 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.NameXPtg;
import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.Ref3DPtg; import org.apache.poi.ss.formula.ptg.Ref3DPtg;
@ -279,17 +280,25 @@ public final class OperationEvaluationContext {
SheetRefEvaluator sre = createExternSheetRefEvaluator(rptg.getSheetName(), rptg.getExternalWorkbookNumber()); SheetRefEvaluator sre = createExternSheetRefEvaluator(rptg.getSheetName(), rptg.getExternalWorkbookNumber());
return new LazyRefEval(rptg.getRow(), rptg.getColumn(), sre); return new LazyRefEval(rptg.getRow(), rptg.getColumn(), sre);
} }
public ValueEval getAreaEval(int firstRowIndex, int firstColumnIndex, public ValueEval getAreaEval(int firstRowIndex, int firstColumnIndex,
int lastRowIndex, int lastColumnIndex) { int lastRowIndex, int lastColumnIndex) {
SheetRefEvaluator sre = getRefEvaluatorForCurrentSheet(); SheetRefEvaluator sre = getRefEvaluatorForCurrentSheet();
return new LazyAreaEval(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex, sre); return new LazyAreaEval(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex, sre);
} }
public ValueEval getArea3DEval(int firstRowIndex, int firstColumnIndex, public ValueEval getArea3DEval(Area3DPtg aptg) {
int lastRowIndex, int lastColumnIndex, int extSheetIndex) { SheetRefEvaluator sre = createExternSheetRefEvaluator(aptg.getExternSheetIndex());
SheetRefEvaluator sre = createExternSheetRefEvaluator(extSheetIndex); return new LazyAreaEval(aptg.getFirstRow(), aptg.getFirstColumn(),
return new LazyAreaEval(firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex, sre); 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) { public ValueEval getNameXEval(NameXPtg nameXPtg) {
// TODO Need HSSF and XSSF versions of these
ExternalSheet externSheet = _workbook.getExternalSheet(nameXPtg.getSheetRefIndex()); ExternalSheet externSheet = _workbook.getExternalSheet(nameXPtg.getSheetRefIndex());
if(externSheet == null) if(externSheet == null)
return new NameXEval(nameXPtg); 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.Function;
import org.apache.poi.ss.formula.functions.IfFunc; import org.apache.poi.ss.formula.functions.IfFunc;
import org.apache.poi.ss.formula.ptg.Area3DPtg; 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.AreaErrPtg;
import org.apache.poi.ss.formula.ptg.AreaPtg; import org.apache.poi.ss.formula.ptg.AreaPtg;
import org.apache.poi.ss.formula.ptg.AttrPtg; import org.apache.poi.ss.formula.ptg.AttrPtg;
@ -679,8 +680,10 @@ public final class WorkbookEvaluator {
return ec.getRef3DEval((Ref3DPxg)ptg); return ec.getRef3DEval((Ref3DPxg)ptg);
} }
if (ptg instanceof Area3DPtg) { if (ptg instanceof Area3DPtg) {
Area3DPtg aptg = (Area3DPtg) ptg; return ec.getArea3DEval((Area3DPtg)ptg);
return ec.getArea3DEval(aptg.getFirstRow(), aptg.getFirstColumn(), aptg.getLastRow(), aptg.getLastColumn(), aptg.getExternSheetIndex()); }
if (ptg instanceof Area3DPxg) {
return ec.getArea3DEval((Area3DPxg)ptg);
} }
if (ptg instanceof RefPtg) { if (ptg instanceof RefPtg) {
RefPtg rptg = (RefPtg) ptg; RefPtg rptg = (RefPtg) ptg;

View File

@ -25,12 +25,13 @@ import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutput;
/** /**
* Title: Area 3D Ptg - 3D reference (Sheet + Area)<P> * <p>Title: Area 3D Ptg - 3D reference (Sheet + Area)</p>
* Description: Defined a area in Extern Sheet. <P> * <p>Description: Defined an area in Extern Sheet. </p>
* REFERENCE: <P> * <p>REFERENCE: </p>
* @author Libin Roman (Vista Portal LDT. Developer) *
* @author avik * <p>This is HSSF only, as it matches the HSSF file format way of
* @author Jason Height (jheight at chariot dot net dot au) * 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 class Area3DPtg extends AreaPtgBase implements WorkbookDependentFormula, ExternSheetReferenceToken {
public final static byte sid = 0x3b; 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.FormulaType;
import org.apache.poi.ss.formula.SheetIdentifier; import org.apache.poi.ss.formula.SheetIdentifier;
import org.apache.poi.ss.formula.functions.FreeRefFunction; 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.NamePtg;
import org.apache.poi.ss.formula.ptg.NameXPtg; import org.apache.poi.ss.formula.ptg.NameXPtg;
import org.apache.poi.ss.formula.ptg.Ptg; 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) { public Ptg get3DReferencePtg(AreaReference area, SheetIdentifier sheet) {
// TODO Implement properly String sheetName = sheet._sheetIdentifier.getName();
return new Area3DPtg(area, getExternalSheetIndex(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) { public String resolveNameXText(NameXPtg n) {