@Test
public void testSetDefaultCellStyle() {
SpreadsheetDocument outputDocument;
OdfContentDom contentDom; // the document object model for content.xml
// the office:automatic-styles element in content.xml
OdfOfficeAutomaticStyles contentAutoStyles;
OdfStyle style;
String noaaDateStyleName;
String noaaTempStyleName;
try {
outputDocument = SpreadsheetDocument.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");
Table table = Table.newTable(outputDocument);
List<Column> columns = table.insertColumnsBefore(0, 3);
Column column = columns.get(0);
column.setDefaultCellStyle(contentAutoStyles.getStyle(noaaDateStyleName, OdfStyleFamily.TableCell));
Cell aCell = column.getCellByIndex(0);
aCell.setValueType("date");
String format = aCell.getFormatString();
Assert.assertEquals("yyyy-MM-dd", format);
List<Row> rows = table.insertRowsBefore(0, 1);
Row row = rows.get(0);
row.setDefaultCellStyle(contentAutoStyles.getStyle(noaaTempStyleName, OdfStyleFamily.TableCell));
Cell bCell = row.getCellByIndex(0);
bCell.setValueType("float");
String bformat = bCell.getFormatString();
Assert.assertEquals("#0.00", bformat);
Assert.assertEquals("end", bCell.getHorizontalAlignment());