@Test public void testGeneralCellValue1() { SBook book = SBooks.createBook("book1"); SSheet sheet = book.createSheet("Sheet 1"); Date now = new Date(); ErrorValue err = new ErrorValue(ErrorValue.INVALID_FORMULA); SCell cell = sheet.getCell(1, 1); Assert.assertEquals(CellType.BLANK, cell.getType()); Assert.assertNull(cell.getValue()); SRanges.range(sheet, 1, 1).setEditText("abc"); Assert.assertEquals(CellType.STRING, cell.getType()); Assert.assertEquals("abc", cell.getValue()); SRanges.range(sheet, 1, 1).setEditText("123"); Assert.assertEquals(CellType.NUMBER, cell.getType()); Assert.assertEquals(123, cell.getNumberValue().intValue()); SRanges.range(sheet, 1, 1).setEditText("2013/01/01"); Assert.assertEquals(CellType.NUMBER, cell.getType()); Assert.assertEquals( "2013/01/01", new SimpleDateFormat("yyyy/MM/dd").format((Date) cell.getDateValue())); SRanges.range(sheet, 1, 1).setEditText("tRue"); Assert.assertEquals(CellType.BOOLEAN, cell.getType()); Assert.assertEquals(Boolean.TRUE, cell.getBooleanValue()); SRanges.range(sheet, 1, 1).setEditText("FalSe"); Assert.assertEquals(CellType.BOOLEAN, cell.getType()); Assert.assertEquals(Boolean.FALSE, cell.getBooleanValue()); SRanges.range(sheet, 1, 1).setEditText("=SUM(999)"); Assert.assertEquals(CellType.FORMULA, cell.getType()); Assert.assertEquals(CellType.NUMBER, cell.getFormulaResultType()); Assert.assertEquals("SUM(999)", cell.getFormulaValue()); Assert.assertEquals(999D, cell.getValue()); try { SRanges.range(sheet, 1, 1).setEditText("=SUM)((999)"); Assert.fail("not here"); } catch (InvalidModelOpException x) { // old value Assert.assertEquals(CellType.FORMULA, cell.getType()); Assert.assertEquals(CellType.NUMBER, cell.getFormulaResultType()); Assert.assertEquals("SUM(999)", cell.getFormulaValue()); Assert.assertEquals(999D, cell.getValue()); } SRanges.range(sheet, 1, 1).setEditText(""); Assert.assertEquals(CellType.BLANK, cell.getType()); Assert.assertEquals(null, cell.getValue()); }
@Test public void testGeneralCellValue2() { SBook book = SBooks.createBook("book1"); SSheet sheet = book.createSheet("Sheet 1"); Date now = new Date(); ErrorValue err = new ErrorValue(ErrorValue.INVALID_FORMULA); SCell cell = sheet.getCell(1, 1); Assert.assertEquals(CellType.BLANK, cell.getType()); Assert.assertNull(cell.getValue()); SRanges.range(sheet, 1, 1).setValue("abc"); Assert.assertEquals(CellType.STRING, cell.getType()); Assert.assertEquals("abc", cell.getValue()); SRanges.range(sheet, 1, 1).setValue(123D); Assert.assertEquals(CellType.NUMBER, cell.getType()); Assert.assertEquals(123D, cell.getValue()); SRanges.range(sheet, 1, 1).setValue(now); Assert.assertEquals(CellType.NUMBER, cell.getType()); Assert.assertEquals(now, cell.getDateValue()); SRanges.range(sheet, 1, 1).setValue(Boolean.TRUE); Assert.assertEquals(CellType.BOOLEAN, cell.getType()); Assert.assertEquals(Boolean.TRUE, cell.getValue()); SRanges.range(sheet, 1, 1).setValue("=SUM(999)"); Assert.assertEquals(CellType.FORMULA, cell.getType()); Assert.assertEquals(CellType.NUMBER, cell.getFormulaResultType()); Assert.assertEquals("SUM(999)", cell.getFormulaValue()); Assert.assertEquals(999D, cell.getValue()); try { SRanges.range(sheet, 1, 1).setValue("=SUM)((999)"); Assert.fail("not here"); } catch (InvalidModelOpException x) { Assert.assertEquals(CellType.FORMULA, cell.getType()); Assert.assertEquals(CellType.NUMBER, cell.getFormulaResultType()); Assert.assertEquals("SUM(999)", cell.getFormulaValue()); Assert.assertEquals(999D, cell.getValue()); } SRanges.range(sheet, 1, 1).setValue(""); Assert.assertEquals(CellType.STRING, cell.getType()); Assert.assertEquals("", cell.getValue()); }