List of usage examples for org.apache.poi.ss.usermodel CellStyle getBorderRight
BorderStyle getBorderRight();
From source file:cn.edu.zucc.chenxg.preview.ToHtml.java
License:Apache License
private void borderStyles(CellStyle style) { styleOut("border-left", style.getBorderLeft(), BORDER); styleOut("border-right", style.getBorderRight(), BORDER); styleOut("border-top", style.getBorderTop(), BORDER); styleOut("border-bottom", style.getBorderBottom(), BORDER); }
From source file:com.canoo.webtest.plugins.exceltest.ExcelVerifyCellStyle.java
License:Open Source License
short getBorder(final CellStyle cellStyle, final int index) { switch (index) { case TOP://from www.j a v a 2 s .co m return cellStyle.getBorderTop(); case RIGHT: return cellStyle.getBorderRight(); case BOTTOM: return cellStyle.getBorderBottom(); case LEFT: return cellStyle.getBorderLeft(); default: throw new IllegalArgumentException("Invalid side: " + index); } }
From source file:com.ncc.excel.test.ExcelUtil.java
License:Apache License
/** * ????? //w w w .ja va 2s . c o m * * @param fromStyle * @param toStyle */ public static void copyCellStyle(CellStyle fromStyle, CellStyle toStyle) { toStyle.setAlignment(fromStyle.getAlignment()); // toStyle.setBorderBottom(fromStyle.getBorderBottom()); toStyle.setBorderLeft(fromStyle.getBorderLeft()); toStyle.setBorderRight(fromStyle.getBorderRight()); toStyle.setBorderTop(fromStyle.getBorderTop()); toStyle.setTopBorderColor(fromStyle.getTopBorderColor()); toStyle.setBottomBorderColor(fromStyle.getBottomBorderColor()); toStyle.setRightBorderColor(fromStyle.getRightBorderColor()); toStyle.setLeftBorderColor(fromStyle.getLeftBorderColor()); // ? toStyle.setFillBackgroundColor(fromStyle.getFillBackgroundColor()); toStyle.setFillForegroundColor(fromStyle.getFillForegroundColor()); // ?? toStyle.setDataFormat(fromStyle.getDataFormat()); toStyle.setFillPattern(fromStyle.getFillPattern()); // toStyle.setFont(fromStyle.getFont(null)); toStyle.setHidden(fromStyle.getHidden()); toStyle.setIndention(fromStyle.getIndention());// toStyle.setLocked(fromStyle.getLocked()); toStyle.setRotation(fromStyle.getRotation());// toStyle.setVerticalAlignment(fromStyle.getVerticalAlignment()); toStyle.setWrapText(fromStyle.getWrapText()); }
From source file:com.vaadin.addon.spreadsheet.SpreadsheetStyleFactory.java
License:Open Source License
private String getBorderRightStyle(CellStyle cellStyle) { StringBuilder sb = new StringBuilder(); BorderStyle borderRight = BORDER.get(cellStyle.getBorderRight()); if (cellStyle instanceof XSSFCellStyle && !((XSSFCellStyle) cellStyle).getCoreXf().getApplyBorder()) { // borders from theme are not working in POI 3.9 final CTXf _cellXf = ((XSSFCellStyle) cellStyle).getCoreXf(); int idx = (int) _cellXf.getBorderId(); CTBorder ct = ((XSSFWorkbook) spreadsheet.getWorkbook()).getStylesSource().getBorderAt(idx) .getCTBorder();/* w ww. j a va 2 s. c o m*/ if (borderRight == BorderStyle.NONE) { STBorderStyle.Enum ptrn = ct.isSetRight() ? ct.getRight().getStyle() : null; if (ptrn != null) { Short key = (short) (ptrn.intValue() - 1); borderRight = BORDER.get(key); } } } if (borderRight != BorderStyle.NONE) { sb.append("border-right:"); sb.append(borderRight.getBorderAttributeValue()); sb.append(colorConverter.getBorderColorCSS(BorderSide.RIGHT, "border-right-color", cellStyle)); } return sb.toString(); }
From source file:com.vaadin.addon.spreadsheet.SpreadsheetStyleFactory.java
License:Open Source License
private void borderStyles(StringBuilder sb, CellStyle cellStyle) { BorderStyle borderLeft = BORDER.get(cellStyle.getBorderLeft()); BorderStyle borderRight = BORDER.get(cellStyle.getBorderRight()); BorderStyle borderTop = BORDER.get(cellStyle.getBorderTop()); BorderStyle borderBottom = BORDER.get(cellStyle.getBorderBottom()); if (cellStyle instanceof XSSFCellStyle && !((XSSFCellStyle) cellStyle).getCoreXf().getApplyBorder()) { // borders from theme are not working in POI 3.9 final CTXf _cellXf = ((XSSFCellStyle) cellStyle).getCoreXf(); int idx = (int) _cellXf.getBorderId(); CTBorder ct = ((XSSFWorkbook) spreadsheet.getWorkbook()).getStylesSource().getBorderAt(idx) .getCTBorder();//ww w . j a v a 2 s. c o m if (borderLeft == BorderStyle.NONE) { STBorderStyle.Enum ptrn = ct.isSetLeft() ? ct.getLeft().getStyle() : null; if (ptrn != null) { Short key = (short) (ptrn.intValue() - 1); borderLeft = BORDER.get(key); } } if (borderRight == BorderStyle.NONE) { STBorderStyle.Enum ptrn = ct.isSetRight() ? ct.getRight().getStyle() : null; if (ptrn != null) { Short key = (short) (ptrn.intValue() - 1); borderRight = BORDER.get(key); } } if (borderBottom == BorderStyle.NONE) { STBorderStyle.Enum ptrn = ct.isSetBottom() ? ct.getBottom().getStyle() : null; if (ptrn != null) { Short key = (short) (ptrn.intValue() - 1); borderBottom = BORDER.get(key); } } if (borderTop == BorderStyle.NONE) { STBorderStyle.Enum ptrn = ct.isSetTop() ? ct.getTop().getStyle() : null; if (ptrn != null) { Short key = (short) (ptrn.intValue() - 1); borderTop = BORDER.get(key); } } } if (borderRight != BorderStyle.NONE) { sb.append("border-right:"); sb.append(borderRight.getBorderAttributeValue()); sb.append(colorConverter.getBorderColorCSS(BorderSide.RIGHT, "border-right-color", cellStyle)); } if (borderBottom != BorderStyle.NONE) { sb.append("border-bottom:"); sb.append(borderBottom.getBorderAttributeValue()); sb.append(colorConverter.getBorderColorCSS(BorderSide.BOTTOM, "border-bottom-color", cellStyle)); } // the top and right borders are transferred to previous cells if (borderTop != BorderStyle.NONE || borderLeft != BorderStyle.NONE) { if (borderTop != BorderStyle.NONE) { final StringBuilder sb2 = new StringBuilder("{border-bottom:"); sb2.append(borderTop.getBorderAttributeValue()); sb2.append(colorConverter.getBorderColorCSS(BorderSide.TOP, "border-bottom-color", cellStyle)); sb2.append("}"); shiftedBorderTopStyles.put((int) cellStyle.getIndex(), sb2.toString()); } if (borderLeft != BorderStyle.NONE) { final StringBuilder sb2 = new StringBuilder("{border-right:"); sb2.append(borderLeft.getBorderAttributeValue()); sb2.append(colorConverter.getBorderColorCSS(BorderSide.LEFT, "border-right-color", cellStyle)); sb2.append("}"); shiftedBorderLeftStyles.put((int) cellStyle.getIndex(), sb2.toString()); } } }
From source file:de.topicmapslab.jexc.eXql.grammar.expression.ValueExpression.java
License:Apache License
/** * Returns the cell value represent by the given token * /*from w w w . j av a 2s. c o m*/ * @param cell * the cell to extract the values from cell * @param token * the token specifies the value to extract * @return the cell value * @throws JeXcException * thrown if cell value token is unknown */ public Object getCellValue(final Cell cell, final String token) throws JeXcException { if (VALUE.equalsIgnoreCase(token) || VALUE_STRING.equalsIgnoreCase(token)) { switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: Double d = cell.getNumericCellValue(); Long l = d.longValue(); /* * check if long value represents the same numeric value then * the double origin */ if (d.doubleValue() == l.longValue()) { return String.valueOf(l); } return String.valueOf(d); case Cell.CELL_TYPE_BOOLEAN: return String.valueOf(cell.getBooleanCellValue()); case Cell.CELL_TYPE_STRING: default: return cell.getStringCellValue(); } } else if (VALUE_DATE.equalsIgnoreCase(token)) { return cell.getDateCellValue(); } else if (VALUE_NUMERICAL.equalsIgnoreCase(token)) { return cell.getNumericCellValue(); } else if (STYLE_FOREGROUND.equalsIgnoreCase(token)) { CellStyle style = cell.getCellStyle(); return style == null ? NULL : style.getFillForegroundColor(); } else if (STYLE_BACKGROUND.equalsIgnoreCase(token)) { CellStyle style = cell.getCellStyle(); return style == null ? NULL : style.getFillBackgroundColor(); } else if (BORDER_TOP.equalsIgnoreCase(token)) { CellStyle style = cell.getCellStyle(); return style == null ? 0 : style.getBorderTop(); } else if (BORDER_BOTTOM.equalsIgnoreCase(token)) { CellStyle style = cell.getCellStyle(); return style == null ? 0 : style.getBorderBottom(); } else if (BORDER_LEFT.equalsIgnoreCase(token)) { CellStyle style = cell.getCellStyle(); return style == null ? 0 : style.getBorderLeft(); } else if (BORDER_RIGHT.equalsIgnoreCase(token)) { CellStyle style = cell.getCellStyle(); return style == null ? 0 : style.getBorderRight(); } else if (ADDRESS.equalsIgnoreCase(token)) { StringBuilder builder = new StringBuilder(); builder.append(cell.getSheet().getSheetName()); builder.append(SLASH); builder.append(cell.getRow().getRowNum()); builder.append(COLON); builder.append(cell.getColumnIndex()); return builder.toString(); } else if (HEIGHT.equalsIgnoreCase(token)) { CellRangeAddress address = XlsxCellUtils.getCellRange(cell); if (address != null) { return address.getLastRow() - address.getFirstRow() + 1; } return 1; } else if (ROW.equalsIgnoreCase(token)) { return cell.getRowIndex(); } else if (COLUMN.equalsIgnoreCase(token)) { return cell.getColumnIndex(); } throw new JeXcException("Unknown constant '" + token + "'!"); }
From source file:net.ceos.project.poi.annotated.core.CellStyleHandler.java
License:Apache License
/** * Clone a cell style passed as parameter. * //w ww . j a va2 s.com * @param wb * the {@link Workbook} in use * @param csBase * the {@link CellStyle} base * @return the new cell style */ private static CellStyle cloneCellStyle(final Workbook wb, final CellStyle csBase) { CellStyle cs = cellStyleFactory.newInstance(wb); cs.setAlignment(csBase.getAlignment()); cs.setVerticalAlignment(csBase.getVerticalAlignment()); cs.setBorderTop(csBase.getBorderTop()); cs.setBorderBottom(csBase.getBorderBottom()); cs.setBorderLeft(csBase.getBorderLeft()); cs.setBorderRight(csBase.getBorderRight()); cs.setFillForegroundColor(csBase.getFillForegroundColor()); cs.setFillPattern(csBase.getFillPattern()); cs.setWrapText(csBase.getWrapText()); cs.setFont(wb.getFontAt(csBase.getFontIndex())); return cs; }
From source file:net.ceos.project.poi.annotated.core.ConditionalFormattingHandler.java
License:Apache License
/** * Apply the conditional formatting according the values defined at the * respective annotation. Is only available at the declared object, in * another words, at the linked {@link Sheet} with the object. * //from w ww . ja v a 2 s. c o m * @param configCriteria * the {@link XConfigCriteria} * @param conditionalFomat * the {@link XlsConditionalFormat} * @throws ConfigurationException */ protected static void applyCondition(XConfigCriteria configCriteria, XlsConditionalFormat conditionalFomat) throws ConfigurationException { // Define a Conditional Formatting rule, which triggers formatting // according the developer definition and applies patternFormatting SheetConditionalFormatting sheet = configCriteria.getSheet().getSheetConditionalFormatting(); /* apply all rules defined */ int i = 0; ConditionalFormattingRule[] rules = new ConditionalFormattingRule[conditionalFomat.rules().length]; XlsConditionalFormatRules[] rulesAnnotated = conditionalFomat.rules(); for (XlsConditionalFormatRules rule : rulesAnnotated) { ConditionalFormattingRule setRule = sheet.createConditionalFormattingRule(rule.operator(), rule.formula1(), StringUtils.isNotBlank(rule.formula2()) ? rule.formula2() : null); CellStyle decorator = null; try { decorator = configCriteria.getCellStyle(conditionalFomat.decorator()); } catch (ElementException e) { throw new ConfigurationException(ExceptionMessage.CONFIGURATION_DECORATOR_MISSING.getMessage(), e); } /* add FontFormatting */ FontFormatting fontFormat = setRule.createFontFormatting(); Font f = configCriteria.getWorkbook().getFontAt(decorator.getFontIndex()); fontFormat.setFontStyle(f.getItalic(), f.getBold()); fontFormat.setFontColorIndex(f.getColor()); fontFormat.setUnderlineType(f.getUnderline()); /* add BorderFormatting */ BorderFormatting borderFormat = setRule.createBorderFormatting(); borderFormat.setBorderBottom(decorator.getBorderBottom()); borderFormat.setBorderTop(decorator.getBorderTop()); borderFormat.setBorderLeft(decorator.getBorderLeft()); borderFormat.setBorderRight(decorator.getBorderRight()); borderFormat.setBottomBorderColor(decorator.getBottomBorderColor()); borderFormat.setTopBorderColor(decorator.getTopBorderColor()); borderFormat.setLeftBorderColor(decorator.getLeftBorderColor()); borderFormat.setRightBorderColor(decorator.getRightBorderColor()); /* add PatternFormatting */ PatternFormatting patternFormat = setRule.createPatternFormatting(); patternFormat.setFillBackgroundColor(decorator.getFillForegroundColor()); /* join rule */ rules[i++] = setRule; } /* Define a region */ CellRangeAddress[] regions = { CellRangeAddress.valueOf(CellFormulaConverter .calculateRangeAddressFromTemplate(configCriteria, conditionalFomat.rangeAddress())) }; /* Apply Conditional Formatting rule defined above to the regions */ sheet.addConditionalFormatting(regions, rules); }
From source file:org.drugepi.table.CellStyleLookup.java
License:Mozilla Public License
public static String styleToString(CellStyle style) { StringBuffer sb = new StringBuffer(); sb.append("getDataFormatString=" + style.getDataFormatString() + "\n"); sb.append("getFontIndex=" + style.getFontIndex() + "\n"); sb.append("getHidden=" + style.getHidden() + "\n"); sb.append("getAlignment=" + style.getAlignment() + "\n"); sb.append("getWrapText=" + style.getWrapText() + "\n"); sb.append("getVerticalAlignment=" + style.getVerticalAlignment() + "\n"); sb.append("getRotation=" + style.getRotation() + "\n"); sb.append("getIndention=" + style.getIndention() + "\n"); sb.append("getBorderLeft=" + style.getBorderLeft() + "\n"); sb.append("getBorderRight=" + style.getBorderRight() + "\n"); sb.append("getBorderTop=" + style.getBorderTop() + "\n"); sb.append("getBorderBottom=" + style.getBorderBottom() + "\n"); sb.append("getLeftBorderColor=" + style.getLeftBorderColor() + "\n"); sb.append("getRightBorderColor=" + style.getRightBorderColor() + "\n"); sb.append("getTopBorderColor=" + style.getTopBorderColor() + "\n"); sb.append("getBottomBorderColor=" + style.getBottomBorderColor() + "\n"); sb.append("getFillPattern=" + style.getFillPattern() + "\n"); sb.append("getFillBackgroundColor=" + style.getFillBackgroundColor() + "\n"); sb.append("getFillForegroundColor=" + style.getFillForegroundColor() + "\n"); return sb.toString(); }
From source file:org.netxilia.impexp.impl.PoiUtils.java
License:Open Source License
public static Styles poiStyle2Netxilia(CellStyle poiStyle, Font font, HSSFPalette palette, NetxiliaStyleResolver styleResolver) { List<Style> entries = new ArrayList<Style>(); if (!poiStyle.getWrapText()) { entries.add(DefaultStyle.nowrap.getStyle()); }//from ww w.jav a2 s. c o m // font if (font.getItalic()) { entries.add(DefaultStyle.italic.getStyle()); } if (font.getStrikeout()) { entries.add(DefaultStyle.strikeout.getStyle()); } if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD) { entries.add(DefaultStyle.bold.getStyle()); } if (font.getUnderline() != Font.U_NONE) { entries.add(DefaultStyle.underline.getStyle()); } // borders if (poiStyle.getBorderBottom() != CellStyle.BORDER_NONE) { entries.add(DefaultStyle.borderBottom.getStyle()); } if (poiStyle.getBorderLeft() != CellStyle.BORDER_NONE) { entries.add(DefaultStyle.borderLeft.getStyle()); } if (poiStyle.getBorderTop() != CellStyle.BORDER_NONE) { entries.add(DefaultStyle.borderTop.getStyle()); } if (poiStyle.getBorderRight() != CellStyle.BORDER_NONE) { entries.add(DefaultStyle.borderRight.getStyle()); } // align switch (poiStyle.getAlignment()) { case CellStyle.ALIGN_LEFT: entries.add(DefaultStyle.alignLeft.getStyle()); break; case CellStyle.ALIGN_RIGHT: entries.add(DefaultStyle.alignRight.getStyle()); break; case CellStyle.ALIGN_CENTER: entries.add(DefaultStyle.alignCenter.getStyle()); break; case CellStyle.ALIGN_JUSTIFY: entries.add(DefaultStyle.alignJustify.getStyle()); break; } if (font != null && font.getColor() != 0) { HSSFColor poiForeground = palette.getColor(font.getColor()); if (poiForeground != null && poiForeground != HSSFColor.AUTOMATIC.getInstance()) { Style foregroundDef = styleResolver.approximateForeground(poiForeground.getTriplet()[0], poiForeground.getTriplet()[1], poiForeground.getTriplet()[2]); if (foregroundDef != null) { entries.add(foregroundDef); } } } if (poiStyle.getFillForegroundColor() != 0) { HSSFColor poiBackground = palette.getColor(poiStyle.getFillForegroundColor()); if (poiBackground != null && poiBackground != HSSFColor.AUTOMATIC.getInstance()) { Style backgroundDef = styleResolver.approximateBackground(poiBackground.getTriplet()[0], poiBackground.getTriplet()[1], poiBackground.getTriplet()[2]); if (backgroundDef != null) { entries.add(backgroundDef); } } } return entries.size() > 0 ? Styles.styles(entries) : null; }