use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class InternalWorkbook method cloneFilter.
public NameRecord cloneFilter(int filterDbNameIndex, int newSheetIndex) {
NameRecord origNameRecord = getNameRecord(filterDbNameIndex);
// copy original formula but adjust 3D refs to the new external sheet index
int newExtSheetIx = checkExternSheet(newSheetIndex);
Ptg[] ptgs = origNameRecord.getNameDefinition();
for (int i = 0; i < ptgs.length; i++) {
Ptg ptg = ptgs[i];
if (ptg instanceof Area3DPtg) {
Area3DPtg a3p = (Area3DPtg) ((OperandPtg) ptg).copy();
a3p.setExternSheetIndex(newExtSheetIx);
ptgs[i] = a3p;
} else if (ptg instanceof Ref3DPtg) {
Ref3DPtg r3p = (Ref3DPtg) ((OperandPtg) ptg).copy();
r3p.setExternSheetIndex(newExtSheetIx);
ptgs[i] = r3p;
}
}
NameRecord newNameRecord = createBuiltInName(NameRecord.BUILTIN_FILTER_DB, newSheetIndex + 1);
newNameRecord.setNameDefinition(ptgs);
newNameRecord.setHidden(true);
return newNameRecord;
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class OperationEvaluationContext method getExternalNameXEval.
private ValueEval getExternalNameXEval(ExternalName externName, String workbookName) {
try {
// Fetch the workbook this refers to, and the name as defined with that
WorkbookEvaluator refWorkbookEvaluator = _bookEvaluator.getOtherWorkbookEvaluator(workbookName);
EvaluationName evaluationName = refWorkbookEvaluator.getName(externName.getName(), externName.getIx() - 1);
if (evaluationName != null && evaluationName.hasFormula()) {
if (evaluationName.getNameDefinition().length > 1) {
throw new RuntimeException("Complex name formulas not supported yet");
}
// Need to evaluate the reference in the context of the other book
OperationEvaluationContext refWorkbookContext = new OperationEvaluationContext(refWorkbookEvaluator, refWorkbookEvaluator.getWorkbook(), -1, -1, -1, _tracker);
Ptg ptg = evaluationName.getNameDefinition()[0];
if (ptg instanceof Ref3DPtg) {
Ref3DPtg ref3D = (Ref3DPtg) ptg;
return refWorkbookContext.getRef3DEval(ref3D);
} else if (ptg instanceof Ref3DPxg) {
Ref3DPxg ref3D = (Ref3DPxg) ptg;
return refWorkbookContext.getRef3DEval(ref3D);
} else if (ptg instanceof Area3DPtg) {
Area3DPtg area3D = (Area3DPtg) ptg;
return refWorkbookContext.getArea3DEval(area3D);
} else if (ptg instanceof Area3DPxg) {
Area3DPxg area3D = (Area3DPxg) ptg;
return refWorkbookContext.getArea3DEval(area3D);
}
}
return ErrorEval.REF_INVALID;
} catch (WorkbookNotFoundException wnfe) {
return ErrorEval.REF_INVALID;
}
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class NameRecord method getExternSheetNumber.
/** gets the extern sheet number
* @return extern sheet index
*/
public int getExternSheetNumber() {
Ptg[] tokens = field_13_name_definition.getTokens();
if (tokens.length == 0) {
return 0;
}
Ptg ptg = tokens[0];
if (ptg.getClass() == Area3DPtg.class) {
return ((Area3DPtg) ptg).getExternSheetIndex();
}
if (ptg.getClass() == Ref3DPtg.class) {
return ((Ref3DPtg) ptg).getExternSheetIndex();
}
return 0;
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class HSSFSheet method getRepeatingRowsOrColums.
private CellRangeAddress getRepeatingRowsOrColums(boolean rows) {
NameRecord rec = getBuiltinNameRecord(NameRecord.BUILTIN_PRINT_TITLE);
if (rec == null) {
return null;
}
Ptg[] nameDefinition = rec.getNameDefinition();
if (nameDefinition == null) {
return null;
}
int maxRowIndex = SpreadsheetVersion.EXCEL97.getLastRowIndex();
int maxColIndex = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
for (Ptg ptg : nameDefinition) {
if (ptg instanceof Area3DPtg) {
Area3DPtg areaPtg = (Area3DPtg) ptg;
if (areaPtg.getFirstColumn() == 0 && areaPtg.getLastColumn() == maxColIndex) {
if (rows) {
return new CellRangeAddress(areaPtg.getFirstRow(), areaPtg.getLastRow(), -1, -1);
}
} else if (areaPtg.getFirstRow() == 0 && areaPtg.getLastRow() == maxRowIndex) {
if (!rows) {
return new CellRangeAddress(-1, -1, areaPtg.getFirstColumn(), areaPtg.getLastColumn());
}
}
}
}
return null;
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class EmbeddedObjectRefSubRecord method readRefPtg.
private static Ptg readRefPtg(byte[] formulaRawBytes) {
LittleEndianInput in = new LittleEndianInputStream(new ByteArrayInputStream(formulaRawBytes));
byte ptgSid = in.readByte();
switch(ptgSid) {
case AreaPtg.sid:
return new AreaPtg(in);
case Area3DPtg.sid:
return new Area3DPtg(in);
case RefPtg.sid:
return new RefPtg(in);
case Ref3DPtg.sid:
return new Ref3DPtg(in);
}
return null;
}
Aggregations