use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class HSSFSheet method setAutoFilter.
@Override
public HSSFAutoFilter setAutoFilter(CellRangeAddress range) {
InternalWorkbook workbook = _workbook.getWorkbook();
int sheetIndex = _workbook.getSheetIndex(this);
NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, sheetIndex + 1);
if (name == null) {
name = workbook.createBuiltInName(NameRecord.BUILTIN_FILTER_DB, sheetIndex + 1);
}
int firstRow = range.getFirstRow();
// if row was not given when constructing the range...
if (firstRow == -1) {
firstRow = 0;
}
// The built-in name must consist of a single Area3d Ptg.
Area3DPtg ptg = new Area3DPtg(firstRow, range.getLastRow(), range.getFirstColumn(), range.getLastColumn(), false, false, false, false, sheetIndex);
name.setNameDefinition(new Ptg[] { ptg });
AutoFilterInfoRecord r = new AutoFilterInfoRecord();
// the number of columns that have AutoFilter enabled.
int numcols = 1 + range.getLastColumn() - range.getFirstColumn();
r.setNumEntries((short) numcols);
int idx = _sheet.findFirstRecordLocBySid(DimensionsRecord.sid);
_sheet.getRecords().add(idx, r);
//create a combobox control for each column
HSSFPatriarch p = createDrawingPatriarch();
final int firstColumn = range.getFirstColumn();
final int lastColumn = range.getLastColumn();
for (int col = firstColumn; col <= lastColumn; col++) {
p.createComboBox(new HSSFClientAnchor(0, 0, 0, 0, (short) col, firstRow, (short) (col + 1), firstRow + 1));
}
return new HSSFAutoFilter(this);
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class TestLinkedDataRecord method testLoad.
public void testLoad() {
LinkedDataRecord record = new LinkedDataRecord(TestcaseRecordInputStream.create(0x1051, data));
assertEquals(LinkedDataRecord.LINK_TYPE_VALUES, record.getLinkType());
assertEquals(LinkedDataRecord.REFERENCE_TYPE_WORKSHEET, record.getReferenceType());
assertEquals(0, record.getOptions());
assertEquals(false, record.isCustomNumberFormat());
assertEquals(0, record.getIndexNumberFmtRecord());
Area3DPtg ptgExpected = new Area3DPtg(0, 7936, 0, 0, false, false, false, false, 0);
Ptg ptgActual = record.getFormulaOfLink()[0];
assertEquals(ptgExpected.toString(), ptgActual.toString());
assertEquals(data.length + 4, record.getRecordSize());
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class TestNameRecord method testBug57923.
public void testBug57923() {
NameRecord record = new NameRecord();
assertEquals(0, record.getExternSheetNumber());
record.setNameDefinition(new Ptg[] {});
assertEquals(0, record.getExternSheetNumber());
record.setNameDefinition(new Ptg[] { new NamePtg(1) });
assertEquals(0, record.getExternSheetNumber());
record.setNameDefinition(new Ptg[] { new Area3DPtg("area", 1) });
assertEquals(1, record.getExternSheetNumber());
record.setNameDefinition(new Ptg[] { new Ref3DPtg("A1", 1) });
assertEquals(1, record.getExternSheetNumber());
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class HSSFSheet method setRepeatingRowsAndColumns.
private void setRepeatingRowsAndColumns(CellRangeAddress rowDef, CellRangeAddress colDef) {
int sheetIndex = _workbook.getSheetIndex(this);
int maxRowIndex = SpreadsheetVersion.EXCEL97.getLastRowIndex();
int maxColIndex = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
int col1 = -1;
int col2 = -1;
int row1 = -1;
int row2 = -1;
if (rowDef != null) {
row1 = rowDef.getFirstRow();
row2 = rowDef.getLastRow();
if ((row1 == -1 && row2 != -1) || (row1 > row2) || (row1 < 0 || row1 > maxRowIndex) || (row2 < 0 || row2 > maxRowIndex)) {
throw new IllegalArgumentException("Invalid row range specification");
}
}
if (colDef != null) {
col1 = colDef.getFirstColumn();
col2 = colDef.getLastColumn();
if ((col1 == -1 && col2 != -1) || (col1 > col2) || (col1 < 0 || col1 > maxColIndex) || (col2 < 0 || col2 > maxColIndex)) {
throw new IllegalArgumentException("Invalid column range specification");
}
}
short externSheetIndex = _workbook.getWorkbook().checkExternSheet(sheetIndex);
boolean setBoth = rowDef != null && colDef != null;
boolean removeAll = rowDef == null && colDef == null;
HSSFName name = _workbook.getBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex);
if (removeAll) {
if (name != null) {
_workbook.removeName(name);
}
return;
}
if (name == null) {
name = _workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex);
}
List<Ptg> ptgList = new ArrayList<Ptg>();
if (setBoth) {
// 2 * Area3DPtg.SIZE + UnionPtg.SIZE
final int exprsSize = 2 * 11 + 1;
ptgList.add(new MemFuncPtg(exprsSize));
}
if (colDef != null) {
Area3DPtg colArea = new Area3DPtg(0, maxRowIndex, col1, col2, false, false, false, false, externSheetIndex);
ptgList.add(colArea);
}
if (rowDef != null) {
Area3DPtg rowArea = new Area3DPtg(row1, row2, 0, maxColIndex, false, false, false, false, externSheetIndex);
ptgList.add(rowArea);
}
if (setBoth) {
ptgList.add(UnionPtg.instance);
}
Ptg[] ptgs = new Ptg[ptgList.size()];
ptgList.toArray(ptgs);
name.setNameDefinition(ptgs);
HSSFPrintSetup printSetup = getPrintSetup();
printSetup.setValidSettings(false);
setActive(true);
}
use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.
the class TestHSSFWorkbook method namesToDeleteSheets.
/**
* Checks that us and HSSFName play nicely with named ranges
* that point to deleted sheets
*/
@Test
public void namesToDeleteSheets() throws IOException {
HSSFWorkbook b = HSSFTestDataSamples.openSampleWorkbook("30978-deleted.xls");
assertEquals(3, b.getNumberOfNames());
// Sheet 2 is deleted
assertEquals("Sheet1", b.getSheetName(0));
assertEquals("Sheet3", b.getSheetName(1));
Area3DPtg ptg;
NameRecord nr;
HSSFName n;
/* ======= Name pointing to deleted sheet ====== */
// First at low level
nr = b.getWorkbook().getNameRecord(0);
assertEquals("On2", nr.getNameText());
assertEquals(0, nr.getSheetNumber());
assertEquals(1, nr.getExternSheetNumber());
assertEquals(1, nr.getNameDefinition().length);
ptg = (Area3DPtg) nr.getNameDefinition()[0];
assertEquals(1, ptg.getExternSheetIndex());
assertEquals(0, ptg.getFirstColumn());
assertEquals(0, ptg.getFirstRow());
assertEquals(0, ptg.getLastColumn());
assertEquals(2, ptg.getLastRow());
// Now at high level
n = b.getNameAt(0);
assertEquals("On2", n.getNameName());
assertEquals("", n.getSheetName());
assertEquals("#REF!$A$1:$A$3", n.getRefersToFormula());
/* ======= Name pointing to 1st sheet ====== */
// First at low level
nr = b.getWorkbook().getNameRecord(1);
assertEquals("OnOne", nr.getNameText());
assertEquals(0, nr.getSheetNumber());
assertEquals(0, nr.getExternSheetNumber());
assertEquals(1, nr.getNameDefinition().length);
ptg = (Area3DPtg) nr.getNameDefinition()[0];
assertEquals(0, ptg.getExternSheetIndex());
assertEquals(0, ptg.getFirstColumn());
assertEquals(2, ptg.getFirstRow());
assertEquals(0, ptg.getLastColumn());
assertEquals(3, ptg.getLastRow());
// Now at high level
n = b.getNameAt(1);
assertEquals("OnOne", n.getNameName());
assertEquals("Sheet1", n.getSheetName());
assertEquals("Sheet1!$A$3:$A$4", n.getRefersToFormula());
/* ======= Name pointing to 3rd sheet ====== */
// First at low level
nr = b.getWorkbook().getNameRecord(2);
assertEquals("OnSheet3", nr.getNameText());
assertEquals(0, nr.getSheetNumber());
assertEquals(2, nr.getExternSheetNumber());
assertEquals(1, nr.getNameDefinition().length);
ptg = (Area3DPtg) nr.getNameDefinition()[0];
assertEquals(2, ptg.getExternSheetIndex());
assertEquals(0, ptg.getFirstColumn());
assertEquals(0, ptg.getFirstRow());
assertEquals(0, ptg.getLastColumn());
assertEquals(1, ptg.getLastRow());
// Now at high level
n = b.getNameAt(2);
assertEquals("OnSheet3", n.getNameName());
assertEquals("Sheet3", n.getSheetName());
assertEquals("Sheet3!$A$1:$A$2", n.getRefersToFormula());
b.close();
}
Aggregations