Assert.fail(e.getMessage());
}
saveods();
//test value type adapt function.
OdfSpreadsheetDocument ods;
try {
ods = OdfSpreadsheetDocument.newSpreadsheetDocument();
OdfTable tbl = ods.getTableByName("Sheet1");
OdfTableCell cell;
for (int i = 1; i <= 10; i++) {
cell = tbl.getCellByPosition("A" + i);
cell.setDoubleValue(new Double(i));
}
cell = tbl.getCellByPosition("A11");
cell.setFormula("=sum(A1:A10)");
//contains '#' should be adapted as float.
cell.setFormatString("#,###");
Assert.assertEquals("float", cell.getValueType());
cell = tbl.getCellByPosition("A12");
cell.setFormula("=sum(A1:A10)");
//contains '0' should be adapted as float.
cell.setFormatString("0.00");
Assert.assertEquals("float", cell.getValueType());
} catch (Exception e) {
Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
Assert.fail(e.getMessage());
}
try {
ods = OdfSpreadsheetDocument.newSpreadsheetDocument();
OdfTable tbl = ods.getTableByName("Sheet1");
OdfTableCell cell;
for (int i = 1; i <= 10; i++) {
cell = tbl.getCellByPosition("A" + i);
cell.setPercentageValue(0.1);
}
cell = tbl.getCellByPosition("A11");
cell.setFormula("=sum(A1:A10)");
//contains '%'should be adapted as percentage.
cell.setFormatString("###.0%");
Assert.assertEquals("percentage", cell.getValueType());
} catch (Exception e) {
Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
Assert.fail(e.getMessage());
}
try {
ods = OdfSpreadsheetDocument.newSpreadsheetDocument();
OdfTable tbl = ods.getTableByName("Sheet1");
OdfTableCell cell;
for (int i = 1; i <= 10; i++) {
cell = tbl.getCellByPosition("A" + i);
cell.setDateValue(Calendar.getInstance());
cell.setFormatString("yyyy.MM.dd");
}
cell = tbl.getCellByPosition("A11");
cell.setFormula("=max(A1:A10)");
//contains 'y' 'M' 'd' should be adapted as date.
cell.setFormatString("yyyy.MM.dd");
Assert.assertEquals("date", cell.getValueType());
} catch (Exception e) {
Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
Assert.fail(e.getMessage());
}
try {
ods = OdfSpreadsheetDocument.newSpreadsheetDocument();
OdfTable tbl = ods.getTableByName("Sheet1");
OdfTableCell cell;
for (int i = 1; i <= 10; i++) {
cell = tbl.getCellByPosition("A" + i);
cell.setTimeValue(Calendar.getInstance());
cell.setFormatString("yyyy.MM.dd HH:mm:ss");