List of usage examples for org.apache.poi.xssf.usermodel XSSFBorderFormatting getBorderTop
@Override
public BorderStyle getBorderTop()
From source file:com.vaadin.addon.spreadsheet.ConditionalFormatter.java
/** * @return the new cssIndex/*from ww w. jav a 2s. c om*/ */ private int addBorderFormatting(ConditionalFormatting cf, ConditionalFormattingRule rule, StringBuilder css, int cssIndex) { if (!(rule instanceof XSSFConditionalFormattingRule)) { // HSSF not supported return cssIndex; } XSSFBorderFormatting borderFormatting = (XSSFBorderFormatting) rule.getBorderFormatting(); if (borderFormatting != null) { BorderStyle borderLeft = SpreadsheetStyleFactory.BORDER.get(borderFormatting.getBorderLeft()); BorderStyle borderRight = SpreadsheetStyleFactory.BORDER.get(borderFormatting.getBorderRight()); BorderStyle borderTop = SpreadsheetStyleFactory.BORDER.get(borderFormatting.getBorderTop()); BorderStyle borderBottom = SpreadsheetStyleFactory.BORDER.get(borderFormatting.getBorderBottom()); // In Excel, we can set a border to 'none', which overrides previous // rules. Default is 'not set', in which case we add no CSS. boolean isLeftSet = isBorderSet(borderFormatting, BorderSide.LEFT); boolean isTopSet = isBorderSet(borderFormatting, BorderSide.TOP); boolean isRightSet = isBorderSet(borderFormatting, BorderSide.RIGHT); boolean isBottomSet = isBorderSet(borderFormatting, BorderSide.BOTTOM); if (isRightSet) { css.append("border-right:"); if (borderRight != BorderStyle.NONE) { css.append(borderRight.getBorderAttributeValue()); css.append(colorConverter.getBorderColorCSS(BorderSide.RIGHT, "border-right-color", borderFormatting)); } else { css.append(BORDER_STYLE_DEFAULT); } } if (isBottomSet) { css.append("border-bottom:"); if (borderBottom != BorderStyle.NONE) { css.append(borderBottom.getBorderAttributeValue()); css.append(colorConverter.getBorderColorCSS(BorderSide.BOTTOM, "border-bottom-color", borderFormatting)); } else { css.append(BORDER_STYLE_DEFAULT); } } // top and left borders might be applied to another cell, so store // them with a different index if (isTopSet) { // bottom border for cell above final StringBuilder sb2 = new StringBuilder("border-bottom:"); if (borderTop != BorderStyle.NONE) { sb2.append(borderTop.getBorderAttributeValue()); sb2.append(colorConverter.getBorderColorCSS(BorderSide.TOP, "border-bottom-color", borderFormatting)); spreadsheet.getState().conditionalFormattingStyles.put(cssIndex, sb2.toString()); topBorders.put(cf, cssIndex++); } else { css.append(BORDER_STYLE_DEFAULT); } } if (isLeftSet) { // right border for cell to the left final StringBuilder sb2 = new StringBuilder("border-right:"); if (borderLeft != BorderStyle.NONE) { sb2.append(borderLeft.getBorderAttributeValue()); sb2.append(colorConverter.getBorderColorCSS(BorderSide.LEFT, "border-right-color", borderFormatting)); spreadsheet.getState().conditionalFormattingStyles.put(cssIndex, sb2.toString()); leftBorders.put(cf, cssIndex++); } else { css.append(BORDER_STYLE_DEFAULT); } } } return cssIndex; }