use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestFormulaParser method testBooleanNamedSheet.
@Test
public void testBooleanNamedSheet() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("true");
HSSFCell cell = sheet.createRow(0).createCell(0);
cell.setCellFormula("'true'!B2");
assertEquals("'true'!B2", cell.getCellFormula());
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestFormulaParser method testMultiSheetReference.
@Test
public void testMultiSheetReference() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet("Cash_Flow");
wb.createSheet("Test Sheet");
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
String formula;
// References to a single cell:
// One sheet
cell.setCellFormula("Cash_Flow!A1");
formula = cell.getCellFormula();
assertEquals("Cash_Flow!A1", formula);
// Then the other
cell.setCellFormula("\'Test Sheet\'!A1");
formula = cell.getCellFormula();
assertEquals("\'Test Sheet\'!A1", formula);
// Now both
cell.setCellFormula("Cash_Flow:\'Test Sheet\'!A1");
formula = cell.getCellFormula();
assertEquals("Cash_Flow:\'Test Sheet\'!A1", formula);
// References to a range (area) of cells:
// One sheet
cell.setCellFormula("Cash_Flow!A1:B2");
formula = cell.getCellFormula();
assertEquals("Cash_Flow!A1:B2", formula);
// Then the other
cell.setCellFormula("\'Test Sheet\'!A1:B2");
formula = cell.getCellFormula();
assertEquals("\'Test Sheet\'!A1:B2", formula);
// Now both
cell.setCellFormula("Cash_Flow:\'Test Sheet\'!A1:B2");
formula = cell.getCellFormula();
assertEquals("Cash_Flow:\'Test Sheet\'!A1:B2", formula);
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestWorkbook method testAddNameX.
@Test
public void testAddNameX() throws IOException {
HSSFWorkbook hwb = new HSSFWorkbook();
InternalWorkbook wb = TestHSSFWorkbook.getInternalWorkbook(hwb);
assertNotNull(wb.getNameXPtg("ISODD", AggregatingUDFFinder.DEFAULT));
FreeRefFunction NotImplemented = new FreeRefFunction() {
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
throw new RuntimeException("not implemented");
}
};
/*
* register the two test UDFs in a UDF finder, to be passed to the evaluator
*/
UDFFinder udff1 = new DefaultUDFFinder(new String[] { "myFunc" }, new FreeRefFunction[] { NotImplemented });
UDFFinder udff2 = new DefaultUDFFinder(new String[] { "myFunc2" }, new FreeRefFunction[] { NotImplemented });
UDFFinder udff = new AggregatingUDFFinder(udff1, udff2);
assertNotNull(wb.getNameXPtg("myFunc", udff));
assertNotNull(wb.getNameXPtg("myFunc2", udff));
// myFunc3 is unknown
assertNull(wb.getNameXPtg("myFunc3", udff));
hwb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestArrayRecord method testBug57231.
public void testBug57231() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("57231_MixedGasReport.xls");
HSSFSheet sheet = wb.getSheet("master");
HSSFSheet newSheet = wb.cloneSheet(wb.getSheetIndex(sheet));
int idx = wb.getSheetIndex(newSheet);
wb.setSheetName(idx, "newName");
// Write the output to a file
HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
assertNotNull(wbBack);
assertNotNull(wbBack.getSheet("master"));
assertNotNull(wbBack.getSheet("newName"));
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestRVA method data.
@Parameters(name = "{1}")
public static Collection<Object[]> data() throws Exception {
poifs = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("testRVA.xls"), true);
workbook = new HSSFWorkbook(poifs);
sheet = workbook.getSheetAt(0);
List<Object[]> data = new ArrayList<Object[]>();
for (int rowIdx = 0; true; rowIdx++) {
HSSFRow row = sheet.getRow(rowIdx);
if (row == null) {
break;
}
HSSFCell cell = row.getCell(0);
if (cell == null || cell.getCellTypeEnum() == CellType.BLANK) {
break;
}
String formula = cell.getCellFormula();
data.add(new Object[] { cell, formula });
}
return data;
}
Aggregations