use of org.apache.poi.hssf.record.NameRecord in project poi by apache.
the class HSSFWorkbook method createName.
/** creates a new named range and add it to the model
* @return named range high level
*/
@Override
public HSSFName createName() {
NameRecord nameRecord = workbook.createName();
HSSFName newName = new HSSFName(this, nameRecord);
names.add(newName);
return newName;
}
use of org.apache.poi.hssf.record.NameRecord 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.hssf.record.NameRecord in project poi by apache.
the class TestFormulaParser method testParseComplexName.
/**
* In bug 47078, POI had trouble evaluating a defined name flagged as 'complex'.
* POI should also be able to parse such defined names.
*/
@Test
public void testParseComplexName() throws IOException {
// Mock up a spreadsheet to match the critical details of the sample
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet("Sheet1");
HSSFName definedName = wb.createName();
definedName.setNameName("foo");
definedName.setRefersToFormula("Sheet1!B2");
// Set the complex flag - POI doesn't usually manipulate this flag
NameRecord nameRec = TestHSSFName.getNameRecord(definedName);
// 0x10 -> complex
nameRec.setOptionFlag((short) 0x10);
Ptg[] result;
try {
result = HSSFFormulaParser.parse("1+foo", wb);
} catch (FormulaParseException e) {
if (e.getMessage().equals("Specified name 'foo' is not a range as expected.")) {
fail("Identified bug 47078c");
}
wb.close();
throw e;
}
confirmTokenClasses(result, IntPtg.class, NamePtg.class, AddPtg.class);
wb.close();
}
use of org.apache.poi.hssf.record.NameRecord in project poi by apache.
the class TestLinkTable method testNameCommentRecordBetweenNameRecords.
/**
*
*/
public void testNameCommentRecordBetweenNameRecords() {
final Record[] recs = { new NameRecord(), new NameCommentRecord("name1", "comment1"), new NameRecord(), new NameCommentRecord("name2", "comment2") };
final List<Record> recList = Arrays.asList(recs);
final WorkbookRecordList wrl = new WorkbookRecordList();
final Map<String, NameCommentRecord> commentRecords = new LinkedHashMap<String, NameCommentRecord>();
final LinkTable lt = new LinkTable(recList, 0, wrl, commentRecords);
assertNotNull(lt);
assertEquals(2, commentRecords.size());
//== is intentionally not .equals()!
assertTrue(recs[1] == commentRecords.get("name1"));
//== is intentionally not .equals()!
assertTrue(recs[3] == commentRecords.get("name2"));
assertEquals(2, lt.getNumNames());
}
use of org.apache.poi.hssf.record.NameRecord in project poi by apache.
the class TestBugs method assertNames.
private void assertNames(HSSFWorkbook wb1, InternalWorkbook w) {
for (int i = 0; i < w.getNumNames(); i++) {
NameRecord r = w.getNameRecord(i);
assertTrue(r.getSheetNumber() <= wb1.getNumberOfSheets());
Ptg[] nd = r.getNameDefinition();
assertEquals(1, nd.length);
assertTrue(nd[0] instanceof DeletedArea3DPtg);
}
}
Aggregations