use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestCellFormat method testApplyFormatHasTwoPartsFirstHasConditionSecondIsGeneral.
@Test
public void testApplyFormatHasTwoPartsFirstHasConditionSecondIsGeneral() throws Exception {
// Create a workbook, row and cell to test with
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
CellFormat cf = CellFormat.getInstance("[>=100]0.00;General");
cell.setCellValue(100);
assertEquals("100.00", cf.apply(cell).text);
cell.setCellValue(10);
assertEquals("10", cf.apply(cell).text);
cell.setCellValue(0);
assertEquals("0", cf.apply(cell).text);
cell.setCellValue(-10);
assertEquals("-10", cf.apply(cell).text);
cell.setCellValue("abc");
assertEquals("abc", cf.apply(cell).text);
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestCellFormat method testApplyJLabelCellForAtFormat.
@Test
public void testApplyJLabelCellForAtFormat() throws Exception {
// Create a workbook, row and cell to test with
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell0 = row.createCell(0);
Cell cell1 = row.createCell(1);
Cell cell2 = row.createCell(2);
Cell cell3 = row.createCell(3);
Cell cell4 = row.createCell(4);
CellFormat cf = CellFormat.getInstance("@");
JLabel label0 = new JLabel();
JLabel label1 = new JLabel();
JLabel label2 = new JLabel();
JLabel label3 = new JLabel();
JLabel label4 = new JLabel();
// case CellType.BLANK
CellFormatResult result0 = cf.apply(label0, cell0);
assertEquals("", result0.text);
assertEquals("", label0.getText());
// case CellType.BOOLEAN
cell1.setCellValue(true);
CellFormatResult result1 = cf.apply(label1, cell1);
assertEquals("TRUE", result1.text);
assertEquals("TRUE", label1.getText());
// case CellType.NUMERIC
cell2.setCellValue(1.23);
CellFormatResult result2 = cf.apply(label2, cell2);
assertEquals("1.23", result2.text);
assertEquals("1.23", label2.getText());
cell3.setCellValue(123.0);
CellFormatResult result3 = cf.apply(label3, cell3);
assertEquals("123", result3.text);
assertEquals("123", label3.getText());
// case CellType.STRING
cell4.setCellValue("abc");
CellFormatResult result4 = cf.apply(label4, cell4);
assertEquals("abc", result4.text);
assertEquals("abc", label4.getText());
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestMissingWorkbook method testMissingWorkbookMissing.
public void testMissingWorkbookMissing() throws IOException {
FormulaEvaluator evaluator = mainWorkbook.getCreationHelper().createFormulaEvaluator();
Sheet lSheet = mainWorkbook.getSheetAt(0);
Row lARow = lSheet.getRow(0);
Cell lA1Cell = lARow.getCell(0);
assertEquals(CellType.FORMULA, lA1Cell.getCellTypeEnum());
try {
evaluator.evaluateFormulaCellEnum(lA1Cell);
fail("Missing external workbook reference exception expected!");
} catch (RuntimeException re) {
assertTrue("Unexpected exception: " + re, re.getMessage().indexOf(SOURCE_DUMMY_WORKBOOK_FILENAME) != -1);
}
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestCellFormat method testApplyFormatHasTwoPartsBothHaveCondition.
@Test
public void testApplyFormatHasTwoPartsBothHaveCondition() throws Exception {
// Create a workbook, row and cell to test with
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
CellFormat cf = CellFormat.getInstance("[>=100]0.00;[>=10]0.000");
cell.setCellValue(100);
assertEquals("100.00", cf.apply(cell).text);
cell.setCellValue(10);
assertEquals("10.000", cf.apply(cell).text);
cell.setCellValue(0);
assertEquals(_255_POUND_SIGNS, cf.apply(cell).text);
cell.setCellValue(-0.123456789012345);
assertEquals(_255_POUND_SIGNS, cf.apply(cell).text);
cell.setCellValue(-10);
assertEquals(_255_POUND_SIGNS, cf.apply(cell).text);
cell.setCellValue("abc");
assertEquals("abc", cf.apply(cell).text);
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestCellFormat method testApplyJLabelCellForGeneralFormat.
@Test
public void testApplyJLabelCellForGeneralFormat() throws Exception {
// Create a workbook, row and cell to test with
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell0 = row.createCell(0);
Cell cell1 = row.createCell(1);
Cell cell2 = row.createCell(2);
Cell cell3 = row.createCell(3);
Cell cell4 = row.createCell(4);
CellFormat cf = CellFormat.getInstance("General");
JLabel label0 = new JLabel();
JLabel label1 = new JLabel();
JLabel label2 = new JLabel();
JLabel label3 = new JLabel();
JLabel label4 = new JLabel();
// case CellType.BLANK
CellFormatResult result0 = cf.apply(label0, cell0);
assertEquals("", result0.text);
assertEquals("", label0.getText());
// case CellType.BOOLEAN
cell1.setCellValue(true);
CellFormatResult result1 = cf.apply(label1, cell1);
assertEquals("TRUE", result1.text);
assertEquals("TRUE", label1.getText());
// case CellType.NUMERIC
cell2.setCellValue(1.23);
CellFormatResult result2 = cf.apply(label2, cell2);
assertEquals("1.23", result2.text);
assertEquals("1.23", label2.getText());
cell3.setCellValue(123.0);
CellFormatResult result3 = cf.apply(label3, cell3);
assertEquals("123", result3.text);
assertEquals("123", label3.getText());
// case CellType.STRING
cell4.setCellValue("abc");
CellFormatResult result4 = cf.apply(label4, cell4);
assertEquals("abc", result4.text);
assertEquals("abc", label4.getText());
wb.close();
}
Aggregations