Example usage for org.apache.poi.ss.usermodel CellStyle getLeftBorderColor

List of usage examples for org.apache.poi.ss.usermodel CellStyle getLeftBorderColor

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel CellStyle getLeftBorderColor.

Prototype

short getLeftBorderColor();

Source Link

Document

get the color to use for the left border

Usage

From source file:com.canoo.webtest.plugins.exceltest.ExcelVerifyCellStyle.java

License:Open Source License

short getBorderColor(final CellStyle cellStyle, final int index) {
    switch (index) {
    case TOP:/*  w  w w.j a  va 2 s .c om*/
        return cellStyle.getTopBorderColor();
    case RIGHT:
        return cellStyle.getRightBorderColor();
    case BOTTOM:
        return cellStyle.getBottomBorderColor();
    case LEFT:
        return cellStyle.getLeftBorderColor();
    default:
        throw new IllegalArgumentException("Invalid side: " + index);
    }
}

From source file:com.ncc.excel.test.ExcelUtil.java

License:Apache License

/** 
 * ????? /*from   w  w  w.  j  av a 2s .  c  om*/
 *  
 * @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:guru.qas.martini.report.DefaultState.java

License:Apache License

protected void colorRow(short color, Row row) {
    short firstCellNum = row.getFirstCellNum();
    short lastCellNum = row.getLastCellNum();
    for (int i = firstCellNum; i <= lastCellNum; i++) {
        Cell cell = row.getCell(i);/* ww w  . j av  a  2 s  .  c om*/
        if (null != cell) {
            CellStyle cellStyle = cell.getCellStyle();
            Workbook workbook = cell.getSheet().getWorkbook();
            CellStyle clone = workbook.createCellStyle();

            clone.cloneStyleFrom(cellStyle);
            clone.setFillForegroundColor(color);
            clone.setFillPattern(FillPatternType.SOLID_FOREGROUND);

            BorderStyle borderStyle = cellStyle.getBorderLeftEnum();
            clone.setBorderLeft(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle);
            short borderColor = cellStyle.getLeftBorderColor();
            clone.setLeftBorderColor(0 == borderColor ? IndexedColors.BLACK.getIndex() : borderColor);

            borderStyle = cellStyle.getBorderRightEnum();
            clone.setBorderRight(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle);
            borderColor = cellStyle.getRightBorderColor();
            clone.setRightBorderColor(0 == borderColor ? IndexedColors.BLACK.getIndex() : borderColor);

            borderStyle = cellStyle.getBorderTopEnum();
            clone.setBorderTop(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle);
            borderColor = cellStyle.getTopBorderColor();
            clone.setTopBorderColor(0 == borderColor ? IndexedColors.BLACK.getIndex() : borderColor);

            borderStyle = cellStyle.getBorderBottomEnum();
            clone.setBorderBottom(BorderStyle.NONE == borderStyle ? BorderStyle.THIN : borderStyle);
            borderColor = cellStyle.getBottomBorderColor();
            clone.setBottomBorderColor(borderColor);
            cell.setCellStyle(clone);
        }
    }
}

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.
 * /*ww w .ja  v a 2s. c om*/
 * @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();
}