TableCellProperties { public void setBorders(StyleTypeDefinitions.CellBordersType bordersType, Border border) { switch (bordersType) { case BOTTOM: setBottomBorder(border); break; case LEFT: setLeftBorder(border); break; case RIGHT: setRightBorder(border); break; case TOP: setTopBorder(border); break; case DIAGONALBLTR: setDiagonalBlTr(border); break; case DIAGONALTLBR: setDiagonalTlBr(border); break; case ALL_FOUR: setBorder(border); break; case LEFT_RIGHT: setLeftBorder(border); setRightBorder(border); break; case TOP_BOTTOM: setTopBorder(border); setBottomBorder(border); break; case DIAGONAL_LINES: setDiagonalBlTr(border); setDiagonalTlBr(border); break; case NONE: mElement.removeAttribute(StyleBorderLineWidthAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(FoBorderAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(StyleBorderLineWidthBottomAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(FoBorderBottomAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(StyleBorderLineWidthTopAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(FoBorderTopAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(StyleBorderLineWidthLeftAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(FoBorderLeftAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(StyleBorderLineWidthRightAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(FoBorderRightAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(StyleDiagonalBlTrWidthsAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(StyleDiagonalBlTrAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(StyleDiagonalTlBrWidthsAttribute.ATTRIBUTE_NAME.getQName()); mElement.removeAttribute(StyleDiagonalTlBrAttribute.ATTRIBUTE_NAME.getQName()); } } protected  TableCellProperties(); protected  TableCellProperties(StyleTableCellPropertiesElement properties); void setBorders(StyleTypeDefinitions.CellBordersType bordersType, Border border); Border getBorder(); Border getTopBorder(); Border getLeftBorder(); Border getRightBorder(); Border getBottomBorder(); Border getDiagonalBlTr(); Border getDiagonalTlBr(); void setBottomBorder(Border border); void setTopBorder(Border border); void setLeftBorder(Border border); void setRightBorder(Border border); void setDiagonalBlTr(Border border); void setDiagonalTlBr(Border border); void setBorder(Border border); void setBackgroundColor(Color aColor); Color getBackgroundColor(); void setWrapped(boolean isWrapped); void setVerticalAlignment(StyleTypeDefinitions.VerticalAlignmentType alignType); StyleTypeDefinitions.VerticalAlignmentType getVerticalAlignment(); Boolean isWrapped(); static TableCellProperties getOrCreateTableCellProperties(OdfStyleBase style); static TableCellProperties getTableCellProperties(OdfStyleBase style);  }
@Test public void testSetBorders() { try { Border borderbase = new Border(Color.LIME, 1.0701, 0.0208, 0.0346, SupportedLinearMeasure.CM); borderbase.setLineStyle(StyleTypeDefinitions.LineType.SINGLE); SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument(); Table table = doc.getTableByName("Sheet1"); Cell cell = table.getCellByPosition(2, 2); cell.setBorders(CellBordersType.BOTTOM, borderbase); cell.setBorders(CellBordersType.RIGHT, borderbase); cell.setBorders(CellBordersType.DIAGONALTLBR, borderbase); Border base = cell.getBorder(CellBordersType.BOTTOM); base = cell.getBorder(CellBordersType.RIGHT); base = cell.getBorder(CellBordersType.DIAGONALTLBR); Assert.assertEquals(borderbase, base); Assert.assertEquals(StyleTypeDefinitions.LineType.SINGLE, borderbase.getLineStyle()); doc.save(ResourceUtilities.newTestOutputFile("testSupportedLinearMeasure.ods")); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); Assert.fail(e.getMessage()); } }
@Test public void testSetBorders_NONE() { try { Border borderbase = new Border(Color.LIME, 3.0701, 0.0208, 0.0346, SupportedLinearMeasure.CM); borderbase.setLineStyle(StyleTypeDefinitions.LineType.SINGLE); SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument(); Table table = doc.getTableByName("Sheet1"); Cell cell = table.getCellByPosition(0, 0); cell.setBorders(CellBordersType.RIGHT, borderbase); TableCellProperties styleCell = cell.getStyleHandler().getTableCellPropertiesForWrite(); NamedNodeMap attr = styleCell.mElement.getAttributes(); Node nod = attr.getNamedItem(FoBorderRightAttribute.ATTRIBUTE_NAME.getQName()); Assert.assertEquals("3.0701cm solid #00ff00", nod.getNodeValue()); cell.setBorders(CellBordersType.NONE, borderbase); TableCellProperties styleCell1 = cell.getStyleHandler().getTableCellPropertiesForWrite(); NamedNodeMap attr1 = styleCell1.mElement.getAttributes(); Node nod1 = attr1.getNamedItem(FoBorderRightAttribute.ATTRIBUTE_NAME.getQName()); Assert.assertNull(nod1); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); Assert.fail(e.getMessage()); } }
@Test public void testSetBorders_DIAGONAL_LINES() { try { Border borderbase = new Border(Color.LIME, 3.0701, 0.0208, 0.0346, SupportedLinearMeasure.CM); borderbase.setLineStyle(StyleTypeDefinitions.LineType.SINGLE); SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument(); Table table = doc.getTableByName("Sheet1"); Cell cell = table.getCellByPosition(0, 0); cell.setBorders(CellBordersType.DIAGONAL_LINES, borderbase); TableCellProperties styleCell = cell.getStyleHandler().getTableCellPropertiesForWrite(); NamedNodeMap attr = styleCell.mElement.getAttributes(); Node nod = attr.getNamedItem("style:diagonal-bl-tr"); Assert.assertEquals("3.0701cm solid #00ff00", nod.getNodeValue()); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); Assert.fail(e.getMessage()); } }