use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class TestFormulaParser method testExponentialInSheet.
@Test
public void testExponentialInSheet() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet("Cash_Flow");
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
String formula;
cell.setCellFormula("1.3E21/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "1.3E+21/3", formula);
cell.setCellFormula("-1.3E21/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "-1.3E+21/3", formula);
cell.setCellFormula("1322E21/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "1.322E+24/3", formula);
cell.setCellFormula("-1322E21/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "-1.322E+24/3", formula);
cell.setCellFormula("1.3E1/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "13/3", formula);
cell.setCellFormula("-1.3E1/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "-13/3", formula);
cell.setCellFormula("1.3E-4/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "0.00013/3", formula);
cell.setCellFormula("-1.3E-4/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "-0.00013/3", formula);
cell.setCellFormula("13E-15/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "0.000000000000013/3", formula);
cell.setCellFormula("-13E-15/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "-0.000000000000013/3", formula);
cell.setCellFormula("1.3E3/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "1300/3", formula);
cell.setCellFormula("-1.3E3/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "-1300/3", formula);
cell.setCellFormula("1300000000000000/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "1300000000000000/3", formula);
cell.setCellFormula("-1300000000000000/3");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "-1300000000000000/3", formula);
cell.setCellFormula("-10E-1/3.1E2*4E3/3E4");
formula = cell.getCellFormula();
assertEquals("Exponential formula string", "-1/310*4000/30000", formula);
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFRow 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.HSSFRow 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;
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class TestSheet method testMisplacedMergedCellsRecords_bug45699.
@Test
public void testMisplacedMergedCellsRecords_bug45699() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex45698-22488.xls");
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(3);
HSSFCell cell = row.getCell(4);
if (cell == null) {
fail("Identified bug 45699");
}
assertEquals("Informations", cell.getRichStringCellValue().getString());
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class CellTypes method main.
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
try {
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow(2);
row.createCell(0).setCellValue(1.1);
row.createCell(1).setCellValue(new Date());
row.createCell(2).setCellValue("a string");
row.createCell(3).setCellValue(true);
row.createCell(4).setCellType(CellType.ERROR);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
} finally {
wb.close();
}
}
Aggregations