List of usage examples for org.apache.poi.ss.usermodel ConditionalFormattingRule getBorderFormatting
BorderFormatting getBorderFormatting();
From source file:com.vaadin.addon.spreadsheet.ConditionalFormatter.java
/** * @return the new cssIndex/*w ww. j ava2 s.c o m*/ */ 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; }
From source file:de.jlo.talendcomp.excel.SpreadsheetOutput.java
License:Apache License
private static String describeRule(ConditionalFormattingRule rule) { StringBuilder sb = new StringBuilder(); sb.append("condition:"); ConditionType ct = rule.getConditionType(); if (ct.equals(ConditionType.CELL_VALUE_IS)) { sb.append(" cell value is: "); sb.append(describeRuleComparisonOperator(rule)); } else if (ct.equals(ConditionType.FORMULA)) { sb.append(" formula: "); sb.append(rule.getFormula1());//from w w w . j a v a 2s . co m } else if (ct.equals(ConditionType.FILTER)) { sb.append(" filter: "); sb.append(describeRuleComparisonOperator(rule)); } else if (ct.equals(ConditionType.ICON_SET)) { sb.append(" icon set: "); sb.append(rule.getMultiStateFormatting()); } else if (ct.equals(ConditionType.COLOR_SCALE)) { sb.append(" color-scale: "); sb.append(rule.getColorScaleFormatting()); } else if (ct.equals(ConditionType.DATA_BAR)) { sb.append(" data-bar: "); sb.append(rule.getDataBarFormatting()); } else { sb.append(" type=" + rule.getConditionType()); } sb.append(" formattings:"); if (rule.getBorderFormatting() != null) { sb.append(" [has border formats]"); } if (rule.getFontFormatting() != null) { sb.append(" [has font formattings]"); } if (rule.getPatternFormatting() != null) { sb.append(" [has pattern formattings]"); } return sb.toString(); }