/** {@inheritDoc} */ public void apply(HSSFCell cell, HSSFCellStyle cellStyle, Map<String, String> style) { for (String pos : new String[] {TOP, RIGHT, BOTTOM, LEFT}) { String posName = StringUtils.capitalize(pos.toLowerCase()); // color String colorAttr = BORDER + "-" + pos + "-" + COLOR; HSSFColor poiColor = CssUtils.parseColor(cell.getSheet().getWorkbook(), style.get(colorAttr)); if (poiColor != null) { try { MethodUtils.invokeMethod(cellStyle, "set" + posName + "BorderColor", poiColor.getIndex()); } catch (Exception e) { log.error("Set Border Color Error Caused.", e); } } // width int width = CssUtils.getInt(style.get(BORDER + "-" + pos + "-" + WIDTH)); String styleAttr = BORDER + "-" + pos + "-" + STYLE; String styleValue = style.get(styleAttr); short shortValue = -1; // empty or solid if (StringUtils.isBlank(styleValue) || "solid".equals(styleValue)) { if (width > 2) { shortValue = CellStyle.BORDER_THICK; } else if (width > 1) { shortValue = CellStyle.BORDER_MEDIUM; } else { shortValue = CellStyle.BORDER_THIN; } } else if (ArrayUtils.contains(new String[] {NONE, HIDDEN}, styleValue)) { shortValue = CellStyle.BORDER_NONE; } else if (DOUBLE.equals(styleValue)) { shortValue = CellStyle.BORDER_DOUBLE; } else if (DOTTED.equals(styleValue)) { shortValue = CellStyle.BORDER_DOTTED; } else if (DASHED.equals(styleValue)) { if (width > 1) { shortValue = CellStyle.BORDER_MEDIUM_DASHED; } else { shortValue = CellStyle.BORDER_DASHED; } } // border style if (shortValue != -1) { try { MethodUtils.invokeMethod(cellStyle, "setBorder" + posName, shortValue); } catch (Exception e) { log.error("Set Border Style Error Caused.", e); } } } }
private void setBorderAttr(Map<String, String> mapBorder, String pos, String value) { if (StringUtils.isNotBlank(value)) { String borderColor = null; for (String borderAttr : value.split("\\s+")) { if ((borderColor = CssUtils.processColor(borderAttr)) != null) { setBorderAttr(mapBorder, pos, COLOR, borderColor); } else if (CssUtils.isNum(borderAttr)) { setBorderAttr(mapBorder, pos, WIDTH, borderAttr); } else if (isStyle(borderAttr)) { setBorderAttr(mapBorder, pos, STYLE, borderAttr); } else { log.info("Border Attr [{}] Is Not Suppoted.", borderAttr); } } } }