use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class TestLinkedDataRecord method testStore.
public void testStore() {
LinkedDataRecord record = new LinkedDataRecord();
record.setLinkType(LinkedDataRecord.LINK_TYPE_VALUES);
record.setReferenceType(LinkedDataRecord.REFERENCE_TYPE_WORKSHEET);
record.setOptions((short) 0);
record.setCustomNumberFormat(false);
record.setIndexNumberFmtRecord((short) 0);
Area3DPtg ptg = new Area3DPtg(0, 7936, 0, 0, false, false, false, false, 0);
record.setFormulaOfLink(new Ptg[] { ptg });
byte[] recordBytes = record.serialize();
assertEquals(recordBytes.length - 4, data.length);
for (int i = 0; i < data.length; i++) assertEquals("At offset " + i, data[i], recordBytes[i + 4]);
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class TestAreaReference method testDiscontinousReference.
public void testDiscontinousReference() throws Exception {
InputStream is = HSSFTestDataSamples.openSampleFileStream("44167.xls");
HSSFWorkbook wb = new HSSFWorkbook(is);
InternalWorkbook workbook = TestHSSFWorkbook.getInternalWorkbook(wb);
HSSFEvaluationWorkbook eb = HSSFEvaluationWorkbook.create(wb);
assertEquals(1, wb.getNumberOfNames());
String sheetName = "Tabelle1";
String rawRefA = "$C$10:$C$14";
String rawRefB = "$C$16:$C$18";
String refA = sheetName + "!" + rawRefA;
String refB = sheetName + "!" + rawRefB;
String ref = refA + "," + refB;
// Check the low level record
NameRecord nr = workbook.getNameRecord(0);
assertNotNull(nr);
assertEquals("test", nr.getNameText());
Ptg[] def = nr.getNameDefinition();
assertEquals(4, def.length);
MemFuncPtg ptgA = (MemFuncPtg) def[0];
Area3DPtg ptgB = (Area3DPtg) def[1];
Area3DPtg ptgC = (Area3DPtg) def[2];
UnionPtg ptgD = (UnionPtg) def[3];
assertEquals("", ptgA.toFormulaString());
assertEquals(refA, ptgB.toFormulaString(eb));
assertEquals(refB, ptgC.toFormulaString(eb));
assertEquals(",", ptgD.toFormulaString());
assertEquals(ref, HSSFFormulaParser.toFormulaString(wb, nr.getNameDefinition()));
// Check the high level definition
int idx = wb.getNameIndex("test");
assertEquals(0, idx);
HSSFName aNamedCell = wb.getNameAt(idx);
// Should have 2 references
assertEquals(ref, aNamedCell.getRefersToFormula());
// Check the parsing of the reference into cells
assertFalse(AreaReference.isContiguous(aNamedCell.getRefersToFormula()));
AreaReference[] arefs = AreaReference.generateContiguous(aNamedCell.getRefersToFormula());
assertEquals(2, arefs.length);
assertEquals(refA, arefs[0].formatAsString());
assertEquals(refB, arefs[1].formatAsString());
for (AreaReference ar : arefs) {
confirmResolveCellRef(wb, ar.getFirstCell());
confirmResolveCellRef(wb, ar.getLastCell());
}
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class HSSFChart method createValuesLinkedDataRecord.
private LinkedDataRecord createValuesLinkedDataRecord() {
LinkedDataRecord r = new LinkedDataRecord();
r.setLinkType(LinkedDataRecord.LINK_TYPE_VALUES);
r.setReferenceType(LinkedDataRecord.REFERENCE_TYPE_WORKSHEET);
r.setCustomNumberFormat(false);
r.setIndexNumberFmtRecord((short) 0);
Area3DPtg p = new Area3DPtg(0, 31, 0, 0, false, false, false, false, 0);
r.setFormulaOfLink(new Ptg[] { p });
return r;
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class HSSFChart method createCategoriesLinkedDataRecord.
private LinkedDataRecord createCategoriesLinkedDataRecord() {
LinkedDataRecord r = new LinkedDataRecord();
r.setLinkType(LinkedDataRecord.LINK_TYPE_CATEGORIES);
r.setReferenceType(LinkedDataRecord.REFERENCE_TYPE_WORKSHEET);
r.setCustomNumberFormat(false);
r.setIndexNumberFmtRecord((short) 0);
Area3DPtg p = new Area3DPtg(0, 31, 1, 1, false, false, false, false, 0);
r.setFormulaOfLink(new Ptg[] { p });
return r;
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class TestHSSFSheet method autoFilter.
@Test
public void autoFilter() throws IOException {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet sh = wb1.createSheet();
InternalWorkbook iwb = wb1.getWorkbook();
InternalSheet ish = sh.getSheet();
assertNull(iwb.getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1));
assertNull(ish.findFirstRecordBySid(AutoFilterInfoRecord.sid));
CellRangeAddress range = CellRangeAddress.valueOf("A1:B10");
sh.setAutoFilter(range);
NameRecord name = iwb.getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1);
assertNotNull(name);
// The built-in name for auto-filter must consist of a single Area3d Ptg.
Ptg[] ptg = name.getNameDefinition();
assertEquals("The built-in name for auto-filter must consist of a single Area3d Ptg", 1, ptg.length);
assertTrue("The built-in name for auto-filter must consist of a single Area3d Ptg", ptg[0] instanceof Area3DPtg);
Area3DPtg aref = (Area3DPtg) ptg[0];
assertEquals(range.getFirstColumn(), aref.getFirstColumn());
assertEquals(range.getFirstRow(), aref.getFirstRow());
assertEquals(range.getLastColumn(), aref.getLastColumn());
assertEquals(range.getLastRow(), aref.getLastRow());
// verify AutoFilterInfoRecord
AutoFilterInfoRecord afilter = (AutoFilterInfoRecord) ish.findFirstRecordBySid(AutoFilterInfoRecord.sid);
assertNotNull(afilter);
//filter covers two columns
assertEquals(2, afilter.getNumEntries());
HSSFPatriarch dr = sh.getDrawingPatriarch();
assertNotNull(dr);
HSSFSimpleShape comboBoxShape = (HSSFSimpleShape) dr.getChildren().get(0);
assertEquals(comboBoxShape.getShapeType(), HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX);
// ObjRecord will appear after serializetion
assertNull(ish.findFirstRecordBySid(ObjRecord.sid));
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
sh = wb2.getSheetAt(0);
ish = sh.getSheet();
ObjRecord objRecord = (ObjRecord) ish.findFirstRecordBySid(ObjRecord.sid);
List<SubRecord> subRecords = objRecord.getSubRecords();
assertEquals(3, subRecords.size());
assertTrue(subRecords.get(0) instanceof CommonObjectDataSubRecord);
// must be present, see Bug 51481
assertTrue(subRecords.get(1) instanceof FtCblsSubRecord);
assertTrue(subRecords.get(2) instanceof LbsDataSubRecord);
wb2.close();
}
Aggregations