ODFDOM Tutorial Index > Creating Spreadsheet Documents Using ODFDOM > Utility Routines

Creating a Text Cell

The following code creates a cell with the given style and text content. The text content is used both for the office:string-value attribute of the cell and for a child paragraph. The null parameter to the OdfTextP constructor creates a paragraph without a style name.

private OdfTableTableCell createCell(String cellStyle, String content) { OdfTableTableCell cell = new OdfTableTableCell(contentDom); OdfTextParagraph paragraph = new OdfTextParagraph(contentDom, null, content); cell.setTableStyleNameAttribute(cellStyle); cell.setOfficeStringValueAttribute(content); cell.setOfficeValueTypeAttribute( OfficeValueTypeAttribute.Value.STRING.toString()); cell.appendChild(paragraph); return cell; }

Converting Time to ODF format

private String convertToOdfTime(String hourMinuteSecondTime) { String[] timeParts = hourMinuteSecondTime.split(":"); String result = "PT" + timeParts[0] + "H" + timeParts[1] + "M" + timeParts[2] + "S"; return result; }