public void testSetDefaultCellStyle() {
OdfSpreadsheetDocument outputDocument;
OdfContentDom contentDom; // the document object model for content.xml
OdfStylesDom stylesDom; // the document object model for styles.xml
// the office:automatic-styles element in content.xml
OdfOfficeAutomaticStyles contentAutoStyles;
// the office:styles element in styles.xml
OdfOfficeStyles stylesOfficeStyles;
OdfStyle style;
String noaaDateStyleName;
String noaaTempStyleName;
try {
outputDocument = OdfSpreadsheetDocument.newSpreadsheetDocument();
contentDom = outputDocument.getContentDom();
contentAutoStyles = contentDom.getOrCreateAutomaticStyles();
OdfNumberDateStyle dateStyle = new OdfNumberDateStyle(contentDom,
"yyyy-MM-dd", "numberDateStyle", null);
OdfNumberStyle numberStyle = new OdfNumberStyle(contentDom,
"#0.00", "numberTemperatureStyle");
contentAutoStyles.appendChild(dateStyle);
contentAutoStyles.appendChild(numberStyle);
style = contentAutoStyles.newStyle(OdfStyleFamily.TableCell);
noaaDateStyleName = style.getStyleNameAttribute();
style.setStyleDataStyleNameAttribute("numberDateStyle");
// and for time cells
style = contentAutoStyles.newStyle(OdfStyleFamily.TableCell);
noaaTempStyleName = style.getStyleNameAttribute();
style.setStyleDataStyleNameAttribute("numberTemperatureStyle");
style.setProperty(StyleParagraphPropertiesElement.TextAlign, "end");
OdfTable table = OdfTable.newTable(outputDocument);
List<OdfTableColumn> columns = table.insertColumnsBefore(0, 3);
OdfTableColumn column = columns.get(0);
column.setDefaultCellStyle(
contentAutoStyles.getStyle(noaaDateStyleName,
OdfStyleFamily.TableCell));
OdfTableCell aCell = column.getCellByIndex(0);
aCell.setValueType("date");
String format = aCell.getFormatString();
Assert.assertEquals("yyyy-MM-dd", format);
List<OdfTableRow> rows = table.insertRowsBefore(0, 1);
OdfTableRow row = rows.get(0);
row.setDefaultCellStyle(contentAutoStyles.getStyle(noaaTempStyleName,
OdfStyleFamily.TableCell));
OdfTableCell bCell = row.getCellByIndex(0);
bCell.setValueType("float");
String bformat = bCell.getFormatString();
Assert.assertEquals("#0.00", bformat);