Java 类org.apache.poi.xssf.usermodel.XSSFColor 实例源码

项目:PoiExcelExport    文件:XSSFCellUtil.java   
/**
 * @param wb
 * @param color
 * @param foreGround
 * @return
 */
public static XSSFCellStyle createBackgroundColorXSSFCellStyle(XSSFWorkbook wb,XSSFColor color,short foreGround){
    String message="XSSFWorkbook must not be null!";
    Objects.requireNonNull(wb, () -> message);
    XSSFCellStyle cellStyle=wb.createCellStyle();
    cellStyle.setWrapText(true);
    cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
    cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setBorderTop(BorderStyle.THIN);
    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setFillForegroundColor(color);
    cellStyle.setFillPattern(foreGround);
    return cellStyle;
}
项目:PoiExcelExport2.0    文件:XSSFCellUtil.java   
/**
 * @param wb
 * @param color
 * @param foreGround
 * @return
 */
public static XSSFCellStyle createBackgroundColorXSSFCellStyle(XSSFWorkbook wb,XSSFColor color,short foreGround){
    String message="XSSFWorkbook must not be null!";
    Objects.requireNonNull(wb, () -> message);
    XSSFCellStyle cellStyle=wb.createCellStyle();
    cellStyle.setWrapText(true);
    cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
    cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setBorderTop(BorderStyle.THIN);
    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setFillForegroundColor(color);
    cellStyle.setFillPattern(foreGround);
    return cellStyle;
}
项目:M2Doc    文件:ExcelServices.java   
/**
 * Gets the {@link Color} form the given {@link XSSFColor}.
 * 
 * @param color
 *            the {@link XSSFColor}
 * @return the {@link Color} form the given {@link XSSFColor}
 */
private Color getColor(XSSFColor color) {
    final Color res;

    if (color != null && color.getRGB() != null) {
        final byte[] rgb = color.getRGB();
        final int r = rgb[0] & MASK;
        final int g = rgb[1] & MASK;
        final int b = rgb[2] & MASK;
        res = new Color(r, g, b);
    } else {
        res = null;
    }

    return res;
}
项目:tecsinapse-data-io    文件:TableCellStyle.java   
private void configFont(Font font) {
    font.setBold(isBold());
    font.setItalic(isItalic());
    font.setStrikeout(isStrikeout());
    font.setUnderline(isUnderline() ? Font.U_SINGLE : Font.U_NONE);
    if (getFontSize() != null) {
        font.setFontHeightInPoints(fontSize.shortValue());
    }
    if (getFontColor() != null) {
        if (font instanceof XSSFFont) {
            ((XSSFFont)font).setColor(new XSSFColor(toRgbByte(fontColor)));
        } else {
            font.setColor(fontColor.getIndex());
        }
    }
}
项目:meja    文件:PoiFont.java   
private static org.apache.poi.ss.usermodel.Font createPoiFont(PoiWorkbook workbook, Font other) {
    org.apache.poi.ss.usermodel.Font poiFont = workbook.getPoiWorkbook().createFont();
    poiFont.setFontHeightInPoints((short) Math.round(other.getSizeInPoints()));
    poiFont.setFontName(other.getFamily());

    final org.apache.poi.ss.usermodel.Color poiTextColor = workbook.getPoiColor(other.getColor());
    if (poiFont instanceof HSSFFont && poiTextColor instanceof HSSFColor) {
        poiFont.setColor(((HSSFColor) poiTextColor).getIndex());
    } else if (poiFont instanceof XSSFFont && poiTextColor instanceof XSSFColor) {
        ((XSSFFont) poiFont).setColor((XSSFColor) poiTextColor);
    } else {
        // it should both either be XSSF _or_ HSSF implementations so this
        // line should never be reached.
        throw new IllegalStateException();
    }

    poiFont.setBold(other.isBold());
    poiFont.setItalic(other.isItalic());
    poiFont.setStrikeout(other.isStrikeThrough());
    poiFont.setUnderline(other.isUnderlined() ? org.apache.poi.ss.usermodel.Font.U_SINGLE
            : org.apache.poi.ss.usermodel.Font.U_NONE);

    return poiFont;
}
项目:meja    文件:PoiCellStyle.java   
@Override
public void setBorderStyle(Direction d, BorderStyle borderStyle) {
    org.apache.poi.ss.usermodel.BorderStyle poiBorder = getPoiBorder(borderStyle);
    final Color color = borderStyle.getColor();
    XSSFColor poiColor = color == null ? null : ((PoiXssfWorkbook) workbook).getPoiColor(color);
    switch (d) {
    case NORTH:
        ((XSSFCellStyle) poiCellStyle).setTopBorderColor(poiColor);
        poiCellStyle.setBorderTop(poiBorder);
        break;
    case EAST:
        ((XSSFCellStyle) poiCellStyle).setRightBorderColor(poiColor);
        poiCellStyle.setBorderRight(poiBorder);
        break;
    case SOUTH:
        ((XSSFCellStyle) poiCellStyle).setBottomBorderColor(poiColor);
        poiCellStyle.setBorderBottom(poiBorder);
        break;
    case WEST:
        ((XSSFCellStyle) poiCellStyle).setLeftBorderColor(poiColor);
        poiCellStyle.setBorderLeft(poiBorder);
        break;
    default:
        throw new IllegalArgumentException();
    }
}
项目:ATTIC-osit    文件:ISheetTemplate.java   
/**
 * @param color
 * @param font
 * @return CellStyle
 */
protected XSSFCellStyle getCellStyle(XSSFColor color, Font font) {
    XSSFCellStyle style = wb.createCellStyle();
    style.setFillForegroundColor(color);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setWrapText(true);    // new line

    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());

    if(font != null) style.setFont(font);

    return style;
}
项目:excella-pdfexporter    文件:ReportsTestUtil.java   
/**
 * XSSF色の文字列表現を取得する
 * 
 * @param color XSSF色
 * @return XSSF色の文字列表現
 */
private static String getXSSFColorString( XSSFColor color) {
    StringBuffer sb = new StringBuffer( "[");
    if ( color != null) {
        sb.append( "Indexed=").append( color.getIndexed()).append( ",");
        sb.append( "Rgb=");
        if ( color.getRgb() != null) {
            for ( byte b : color.getRgb()) {
                sb.append( String.format( "%02x", b).toUpperCase());
            }
        }
        sb.append( ",");
        sb.append( "Tint=").append( color.getTint()).append( ",");
        sb.append( "Theme=").append( color.getTheme()).append( ",");
        sb.append( "Auto=").append( color.isAuto());
    }
    return sb.append( "]").toString();
}
项目:excella-core    文件:TestUtil.java   
private static String getXSSFColorString( XSSFColor color) {
    StringBuffer sb = new StringBuffer( "[");
    if ( color != null) {
        sb.append( "Indexed=").append( color.getIndexed()).append( ",");
        sb.append( "Rgb=");
        if ( color.getRGB() != null) {
            for ( byte b : color.getRGB()) {
                sb.append( String.format( "%02x", b).toUpperCase());
            }
        }
        sb.append( ",");
        sb.append( "Tint=").append( color.getTint()).append( ",");
        sb.append( "Theme=").append( color.getTheme()).append( ",");
        sb.append( "Auto=").append( color.isAuto());
    }
    return sb.append( "]").toString();
}
项目:excella-reports    文件:ReportsTestUtil.java   
/**
 * XSSF色の文字列表現を取得する
 * 
 * @param color XSSF色
 * @return XSSF色の文字列表現
 */
private static String getXSSFColorString( XSSFColor color) {
    StringBuffer sb = new StringBuffer( "[");
    if ( color != null) {
        sb.append( "Indexed=").append( color.getIndexed()).append( ",");
        sb.append( "Rgb=");
        if ( color.getRGB() != null) {
            for ( byte b : color.getRGB()) {
                sb.append( String.format( "%02x", b).toUpperCase());
            }
        }
        sb.append( ",");
        sb.append( "Tint=").append( color.getTint()).append( ",");
        sb.append( "Theme=").append( color.getTheme()).append( ",");
        sb.append( "Auto=").append( color.isAuto());
    }
    return sb.append( "]").toString();
}
项目:birt    文件:StyleManagerXUtils.java   
@Override
public void addColourToFont(Workbook workbook, Font font, String colour) {
    if(colour == null) {
        return ;
    }
    if(IStyle.TRANSPARENT_VALUE.equals(colour)) {
        return ;
    }
    if(font instanceof XSSFFont) {
        XSSFFont xFont = (XSSFFont)font;
        XSSFColor xColour = getXColour(colour);

        if(xColour != null) {
            xFont.setColor(xColour);
        }
    }
}
项目:birt    文件:StyleManagerXUtils.java   
@Override
public void addBackgroundColourToStyle(Workbook workbook, CellStyle style, String colour) {
    if(colour == null) {
        return ;
    }
    if(IStyle.TRANSPARENT_VALUE.equals(colour)) {
        return ;
    }
    if(style instanceof XSSFCellStyle) {
        XSSFCellStyle cellStyle = (XSSFCellStyle)style;
        XSSFColor xColour = getXColour(colour);
        if(xColour != null) {
            cellStyle.setFillForegroundColor(xColour);
            cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        }
    }
}
项目:birt    文件:StyleManagerXUtils.java   
@Override
public Font correctFontColorIfBackground( FontManager fm, Workbook wb, BirtStyle birtStyle, Font font ) {
    CSSValue bgColour = birtStyle.getProperty( StyleConstants.STYLE_BACKGROUND_COLOR );
    int bgRgb[] = parseColour( bgColour == null ? null : bgColour.getCssText(), "white" );

    XSSFColor colour = ((XSSFFont)font).getXSSFColor();
    int fgRgb[] = rgbOnly( colour.getARgb() );
    if( ( fgRgb[0] == 255 ) && ( fgRgb[1] == 255 ) && ( fgRgb[2] == 255 ) ) {
        fgRgb[0]=fgRgb[1]=fgRgb[2]=0;
    } else if( ( fgRgb[0] == 0 ) && ( fgRgb[1] == 0 ) && ( fgRgb[2] == 0 ) ) {
        fgRgb[0]=fgRgb[1]=fgRgb[2]=255;
    }

    if( ( bgRgb[ 0 ] == fgRgb[ 0 ] ) && ( bgRgb[ 1 ] == fgRgb[ 1 ] ) && ( bgRgb[ 2 ] == fgRgb[ 2 ] ) ) {

        IStyle addedStyle = new AreaStyle( fm.getCssEngine() );
        addedStyle.setColor( contrastColour( bgRgb ) );

        return fm.getFontWithExtraStyle( font, addedStyle );
    } else {
        return font;
    }
}
项目:excel2canvas    文件:ExcelColor.java   
private static byte[] getRgbWithTint(XSSFColor c) {
    byte[] rgb = c.getCTColor().getRgb();
    double tint = c.getTint();
    if (rgb != null && tint != 0.0) {
        if(rgb.length == 4) {
            byte[] tmp = new byte[3];
            System.arraycopy(rgb, 1, tmp, 0, 3);
            rgb = tmp;
        }
        for (int i=0; i<rgb.length; i++) {
            int lum = rgb[i] & 0xFF;
            double d = sRGB_to_scRGB(lum / 255.0);
            d = tint > 0 ? d * (1.0 - tint) + tint : d * (1 + tint);
            d = scRGB_to_sRGB(d);
            rgb[i] = (byte)Math.round(d * 255.0);
        }
    }
    return rgb;
}
项目:PoiExcelExport    文件:XSSFontUtil.java   
/**
 * @param wb
 * @return {code XSSFFont}
 */
public static XSSFFont createXSSFFont(XSSFWorkbook wb){
    String message="XSSFWorkbook must not be null!";
    Objects.requireNonNull(wb, () -> message);
    XSSFFont cellfont=wb.createFont();
    cellfont.setFontName("新宋体");
    cellfont.setFontHeightInPoints((short) 12);
    cellfont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
    cellfont.setColor(new XSSFColor(new Color(50,73,38)));

    return cellfont;
}
项目:PoiExcelExport    文件:XSSFontUtil.java   
/**
 * @param wb
 * @param fontFamily
 * @param height
 * @param color
 * @param bold
 * @return
 */
public static XSSFFont createColorXSSFFont(XSSFWorkbook wb,String fontFamily,short height,XSSFColor color,boolean bold){
    String message="XSSFWorkbook must not be null!";
    Objects.requireNonNull(wb, () -> message);
    XSSFFont cellfont=wb.createFont();
    cellfont.setFontName(fontFamily);
    cellfont.setFontHeightInPoints(height);
    cellfont.setColor(color);
    if(bold){
        cellfont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
    }
    return cellfont;
}
项目:PoiExcelExport    文件:XSSFCellUtil.java   
/**
 * 返回excel内容字体样式
 * @param wb
 * @return
 */
public static XSSFCellStyle getcontentCellStyle(XSSFWorkbook wb){
    String message="XSSFWorkbook must not be null!";
    Objects.requireNonNull(wb, () -> message);
    XSSFCellStyle contentStyle=createCenterXSSFCellStyle(wb);
    //fill enlarged font
    XSSFFont enlargedFont=XSSFontUtil.createColorXSSFFont(wb, "新宋体", (short) 16, new XSSFColor(Color.WHITE), true);
    contentStyle.setFont(enlargedFont);
    return contentStyle;
}
项目:aem-epic-tool    文件:ReportUtil.java   
public static CellStyle createHeaderStyle(Workbook workbook) {
    XSSFCellStyle headerStyle = createCellStyle(workbook);
    XSSFColor header = new XSSFColor(new byte[]{(byte) 79, (byte) 129, (byte) 189});
    headerStyle.setFillForegroundColor(header);
    headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    headerStyle.getFont().setColor(IndexedColors.WHITE.index);
    return headerStyle;
}
项目:urule    文件:PackageServletHandler.java   
@SuppressWarnings("unchecked")
public void exportExcelTemplate(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    List<VariableCategory> variableCategories=(List<VariableCategory>)httpSessionKnowledgeCache.get(req, VCS_KEY);
    if(variableCategories==null){
        KnowledgeBase knowledgeBase=buildKnowledgeBase(req);
        variableCategories=knowledgeBase.getResourceLibrary().getVariableCategories();
    }
    SXSSFWorkbook wb = new SXSSFWorkbook();
    XSSFCellStyle style=(XSSFCellStyle)wb.createCellStyle();
    Color c=new Color(147,208,15);
    XSSFColor xssfColor=new XSSFColor(c);
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setFillForegroundColor(xssfColor);
    for(VariableCategory vc:variableCategories){
        buildSheet(wb, vc,style);
    }
    resp.setContentType("application/x-xls");
    resp.setHeader("Content-Disposition","attachment; filename=urule-batch-test-template.xlsx");
    OutputStream outputStream=resp.getOutputStream();
    wb.write(outputStream);;
    outputStream.flush();
    outputStream.close();
}
项目:bdf2    文件:TitleStyleBuilder.java   
private XSSFCellStyle createXSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) {
    SXSSFWorkbook workbook = (SXSSFWorkbook) wb;
    XSSFFont titleFont = (XSSFFont) workbook.createFont();
    titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
    titleFont.setFontName("宋体");

    XSSFColor color9 = new XSSFColor(new java.awt.Color(fontColor[0], fontColor[1], fontColor[2]));
    XSSFColor color10 = new XSSFColor(new java.awt.Color(bgColor[0], bgColor[1], bgColor[2]));

    if (!(fontColor[0] == 0 && fontColor[1] == 0 && fontColor[2] == 0)) {
        titleFont.setColor(color9);
    }
    titleFont.setBold(true);
    titleFont.setFontHeightInPoints((short) fontSize);

    XSSFCellStyle titleStyle = (XSSFCellStyle) createBorderCellStyle(workbook, true);
    titleStyle.setFont(titleFont);
    titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    titleStyle.setFillForegroundColor(color10);
    titleStyle.setAlignment(HorizontalAlignment.CENTER);
    titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    return titleStyle;
}
项目:PoiExcelExport2.0    文件:XSSFontUtil.java   
/**
 * @param wb
 * @return {code XSSFFont}
 */
public static XSSFFont createXSSFFont(XSSFWorkbook wb){
    String message="XSSFWorkbook must not be null!";
    Objects.requireNonNull(wb, () -> message);
    XSSFFont cellfont=wb.createFont();
    cellfont.setFontName("新宋体");
    cellfont.setFontHeightInPoints((short) 12);
    cellfont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
    cellfont.setColor(new XSSFColor(new Color(50,73,38)));

    return cellfont;
}
项目:PoiExcelExport2.0    文件:XSSFontUtil.java   
/**
 * @param wb
 * @param fontFamily
 * @param height
 * @param color
 * @param bold
 * @return
 */
public static XSSFFont createColorXSSFFont(XSSFWorkbook wb,String fontFamily,short height,XSSFColor color,boolean bold){
    String message="XSSFWorkbook must not be null!";
    Objects.requireNonNull(wb, () -> message);
    XSSFFont cellfont=wb.createFont();
    cellfont.setFontName(fontFamily);
    cellfont.setFontHeightInPoints(height);
    cellfont.setColor(color);
    if(bold){
        cellfont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
    }
    return cellfont;
}
项目:PoiExcelExport2.0    文件:XSSFCellUtil.java   
public static XSSFCellStyle createTitleXSSFCellStyle(XSSFWorkbook wb){
    String message="XSSFWorkbook must not be null!";
    Objects.requireNonNull(wb, () -> message);
    XSSFCellStyle cellStyle=wb.createCellStyle();
    cellStyle.setWrapText(true);
    cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
    cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setBorderTop(BorderStyle.THIN);
    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setFillForegroundColor(new XSSFColor( new Color(75, 172, 198)));
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    return cellStyle;
}
项目:PoiExcelExport2.0    文件:XSSFCellUtil.java   
/**
 * 返回excel内容字体样式
 * @param wb
 * @return
 */
public static XSSFCellStyle getcontentCellStyle(XSSFWorkbook wb){
    String message="XSSFWorkbook must not be null!";
    Objects.requireNonNull(wb, () -> message);
    XSSFCellStyle contentStyle=createCenterXSSFCellStyle(wb);
    //fill enlarged font
    XSSFFont enlargedFont=XSSFontUtil.createColorXSSFFont(wb, "新宋体", (short) 16, new XSSFColor(Color.WHITE), true);
    contentStyle.setFont(enlargedFont);
    return contentStyle;
}
项目:Gargoyle    文件:ExcelUtil.java   
private static void applyColor(Workbook createNewWorkBookXlsx, ExcelColDVO dvo, Cell createCell) {
    Color backgroundColor = dvo.getBackgroundColor();
    if (backgroundColor != null) {
        XSSFCellStyle style = (XSSFCellStyle) createNewWorkBookXlsx.createCellStyle();
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        style.setFillForegroundColor(new XSSFColor(backgroundColor));
        createCell.setCellStyle(style);
    }
}
项目:Gargoyle    文件:ExcelUtil.java   
private static void applyColor(Workbook createNewWorkBookXlsx, ExcelDataDVO dvo, Cell createCell) {
    Color backgroundColor = dvo.getBackgroundColor();
    if (backgroundColor != null) {
        XSSFCellStyle style = (XSSFCellStyle) createNewWorkBookXlsx.createCellStyle();
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        style.setFillForegroundColor(new XSSFColor(backgroundColor));
        createCell.setCellStyle(style);
    }
}
项目:gedantic    文件:WorkbookCreator.java   
/**
 * Setup styles.
 */
private void setupStyles() {
    styleTitle = wb.createCellStyle();
    Font title_font = wb.createFont();
    title_font.setFontName("Helvetica");
    title_font.setColor(IndexedColors.BLACK.getIndex());
    title_font.setFontHeightInPoints((short) 24);
    styleTitle.setFont(title_font);

    styleSubtitle = wb.createCellStyle();
    Font subtitle_font = wb.createFont();
    subtitle_font.setFontName("Helvetica");
    subtitle_font.setColor(IndexedColors.GREY_50_PERCENT.getIndex());
    subtitle_font.setFontHeightInPoints((short) 18);
    styleSubtitle.setFont(subtitle_font);

    styleHyperlink = wb.createCellStyle();
    Font hlink_font = wb.createFont();
    hlink_font.setFontName("Helvetica");
    hlink_font.setUnderline(Font.U_SINGLE);
    hlink_font.setColor(IndexedColors.BLUE.getIndex());
    styleHyperlink.setFont(hlink_font);

    styleNormal = wb.createCellStyle();
    Font normal_font = wb.createFont();
    normal_font.setFontName("Helvetica");
    normal_font.setColor(IndexedColors.BLACK.getIndex());
    normal_font.setFontHeightInPoints((short) 12);
    styleNormal.setFont(normal_font);
    styleNormal.setWrapText(true);

    styleHeader = wb.createCellStyle();
    Font header_font = wb.createFont();
    header_font.setFontName("Helvetica");
    header_font.setColor(IndexedColors.WHITE.getIndex());
    header_font.setBold(true);
    header_font.setFontHeightInPoints((short) 12);
    XSSFColor bg = new XSSFColor(new java.awt.Color(0x28, 0x60, 0x90));
    ((XSSFCellStyle) styleHeader).setFillForegroundColor(bg);
    styleHeader.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styleHeader.setFont(header_font);

}
项目:poilight    文件:StyleHelper.java   
/**
 * Returns the final color from the three red, green and blue.
 * 
 * @param red the hexadecimal value of the red
 * @param green the hexadecimal value of the green 
 * @param blue the hexadecimal value of the blue
 * @return the final color
 */
public static XSSFColor getColor(int red, int green, int blue) {
  byte[] rgb = new byte[3];
  rgb[0] = (byte) red; 
  rgb[1] = (byte) green; 
  rgb[2] = (byte) blue; 
  return  new XSSFColor(rgb);

}
项目:poilight    文件:CreateExcelStyleHelper.java   
/**
 * Save all the configuration for the body of board in a BoardStyle. We can use
 * later this object to set all the style option
 * 
 * @param isEven indicate if the cell is in a row even or odd
 * @param evenColor the cell color for an even row
 * @param oddColor the cell color for an odd row
 * @param fontColor the font color
 * @param borderColor the border color
 * @param borderStyle the configuration of the cell's border
 * @return a complete configuration for a cell
 */
private static TableStyle getBodyStyle(boolean isEven, XSSFColor evenColor, XSSFColor oddColor, 
                                        XSSFColor fontColor, XSSFColor borderColor, BorderStyle borderStyle) {
  TableStyle body = new TableStyle();
  body.setAlignment(CellStyle.ALIGN_LEFT);
  borderStyle.completeBorderInfo(body);
  body.setFontColor(fontColor);
  if (isEven) {
    body.setFillColor(evenColor);
  } else {
    body.setFillColor(oddColor);
  }
  body.setBorderColor(borderColor);
  return body;
}
项目:poilight    文件:TableStyle.java   
/**
 * Constructor.
 * 
 * @param fontColor the font color
 * @param fillColor the background color
 * @param fontName the font name
 * @param isBold indicate if the font is bold
 * @param fontSize the font size
 * @param alignment the cell's alignment
 */
public TableStyle(XSSFColor fontColor, XSSFColor fillColor, String fontName,
    boolean isBold, short fontSize, short alignment) {
  super();
  this.fontColor = fontColor;
  this.fillColor = fillColor;
  this.fontName = fontName;
  this.isBold = isBold;
  this.fontSize = fontSize;
  this.alignment = alignment;
}
项目:poix    文件:StylerHelper.java   
public void styleColor(Formatter out, String attr, Color color) {
    XSSFColor xSSFColor = (XSSFColor) color;
    if (color == null || xSSFColor.isAuto())
        return;

    byte[] rgb = xSSFColor.getRgb();
    if (rgb == null) {
        return;
    }
    out.format("  %s: #%02x%02x%02x;%n", attr, rgb[0], rgb[1], rgb[2]);
}
项目:vaadin-excel-exporter    文件:ExcelStyleUtil.java   
/**
 * Sets the borders.
 *
 * @param headerCellStyle
 *            the header cell style
 * @param left
 *            the left
 * @param right
 *            the right
 * @param top
 *            the top
 * @param bottom
 *            the bottom
 * @param color
 *            the color
 * @return the XSSF cell style
 */
public static XSSFCellStyle setBorders(final XSSFCellStyle headerCellStyle, final Boolean left, final Boolean right,
        final Boolean top, final Boolean bottom, final Color color) {
    if (bottom) {
        headerCellStyle.setBorderBottom(BorderStyle.THIN);
        headerCellStyle.setBorderColor(BorderSide.BOTTOM, new XSSFColor(color));
    }

    if (top) {
        headerCellStyle.setBorderTop(BorderStyle.THIN);
        headerCellStyle.setBorderColor(BorderSide.TOP, new XSSFColor(color));
    }

    if (left) {
        headerCellStyle.setBorderLeft(BorderStyle.THIN);
        headerCellStyle.setBorderColor(BorderSide.LEFT, new XSSFColor(color));
    }

    if (right) {
        headerCellStyle.setBorderRight(BorderStyle.THIN);
        headerCellStyle.setBorderColor(BorderSide.RIGHT, new XSSFColor(color));
    }

    return headerCellStyle;
}
项目:easypoi    文件:StylerHelper.java   
public void styleColor(Formatter out, String attr, Color color) {
    XSSFColor xSSFColor = (XSSFColor) color;
    if (color == null || xSSFColor.isAuto())
        return;

    byte[] rgb = xSSFColor.getRgb();
    if (rgb == null) {
        return;
    }
    out.format("  %s: #%02x%02x%02x;%n", attr, rgb[0], rgb[1], rgb[2]);
}
项目:JavaWeb    文件:FileUtil.java   
public static XSSFCellStyle setStyle(XSSFWorkbook workbook) {  
    //设置字体;  
    XSSFFont font = workbook.createFont();  
    //设置字体大小;  
    font.setFontHeightInPoints((short) 20);  
    //设置字体名字;  
    font.setFontName("Courier New");  
    //font.setItalic(true);  
    //font.setStrikeout(true);  
    //设置样式;  
    XSSFCellStyle style = workbook.createCellStyle();  
    //设置底边框;  
    style.setBorderBottom(XSSFCellStyle.BORDER_THIN);  
    //设置底边框颜色;  
    style.setBottomBorderColor(new XSSFColor(Color.BLACK));  
    //设置左边框;  
    style.setBorderLeft(XSSFCellStyle.BORDER_THIN);  
    //设置左边框颜色;  
    style.setLeftBorderColor(new XSSFColor(Color.BLACK));  
    //设置右边框;  
    style.setBorderRight(XSSFCellStyle.BORDER_THIN);  
    //设置右边框颜色;  
    style.setRightBorderColor(new XSSFColor(Color.BLACK));  
    //设置顶边框;  
    style.setBorderTop(XSSFCellStyle.BORDER_THIN);  
    //设置顶边框颜色;  
    style.setTopBorderColor(new XSSFColor(Color.BLACK));  
    //在样式用应用设置的字体;  
    style.setFont(font);  
    //设置自动换行;  
    style.setWrapText(false);  
    //设置水平对齐的样式为居中对齐;  
    style.setAlignment(XSSFCellStyle.ALIGN_CENTER);  
    //设置垂直对齐的样式为居中对齐;  
    style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);  
    return style;  
}
项目:JavaWeb    文件:FileUtil.java   
public static XSSFCellStyle setStyle(XSSFWorkbook workbook) {  
    //设置字体;  
    XSSFFont font = workbook.createFont();  
    //设置字体大小;  
    font.setFontHeightInPoints((short) 20);  
    //设置字体名字;  
    font.setFontName("Courier New");  
    //font.setItalic(true);  
    //font.setStrikeout(true);  
    //设置样式;  
    XSSFCellStyle style = workbook.createCellStyle();  
    //设置底边框;  
    style.setBorderBottom(XSSFCellStyle.BORDER_THIN);  
    //设置底边框颜色;  
    style.setBottomBorderColor(new XSSFColor(Color.BLACK));  
    //设置左边框;  
    style.setBorderLeft(XSSFCellStyle.BORDER_THIN);  
    //设置左边框颜色;  
    style.setLeftBorderColor(new XSSFColor(Color.BLACK));  
    //设置右边框;  
    style.setBorderRight(XSSFCellStyle.BORDER_THIN);  
    //设置右边框颜色;  
    style.setRightBorderColor(new XSSFColor(Color.BLACK));  
    //设置顶边框;  
    style.setBorderTop(XSSFCellStyle.BORDER_THIN);  
    //设置顶边框颜色;  
    style.setTopBorderColor(new XSSFColor(Color.BLACK));  
    //在样式用应用设置的字体;  
    style.setFont(font);  
    //设置自动换行;  
    style.setWrapText(false);  
    //设置水平对齐的样式为居中对齐;  
    style.setAlignment(XSSFCellStyle.ALIGN_CENTER);  
    //设置垂直对齐的样式为居中对齐;  
    style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);  
    return style;  
}
项目:tecsinapse-data-io    文件:TableCellStyle.java   
public CellStyle toCellStyle(Workbook wb) {
    CellStyle cellStyle = wb.createCellStyle();

    if (getBackgroundColor() != null) {
        if (cellStyle instanceof XSSFCellStyle) {
            ((XSSFCellStyle)cellStyle).setFillForegroundColor(new XSSFColor(toRgbByte(getBackgroundColor())));
        } else {
            cellStyle.setFillForegroundColor(getBackgroundColor().getIndex());
        }
        cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    }
    if (getBorder() != null) {
        cellStyle = border.toCellStyle(cellStyle);
    }
    if (getvAlign() != null) {
        cellStyle.setVerticalAlignment(vAlign.getCellStyleVAlign());
    }
    if (gethAlign() != null) {
        cellStyle.setAlignment(hAlign.getCellStyleHAlign());
    }
    Font font = wb.createFont();
    configFont(font);
    cellStyle.setFont(font);
    if (cellFormat != null && !cellFormat.isEmpty()) {
        cellStyle.setDataFormat(wb.createDataFormat().getFormat(cellFormat));
    }
    return cellStyle;
}
项目:tecsinapse-data-io    文件:CellStyleBorder.java   
public CellStyle toCellStyle(CellStyle cellStyle) {
    if (cellStyle == null || !left && !right && !bottom && !top) {
        return cellStyle;
    }
    if (left) {
        cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
        if (cellStyle instanceof XSSFCellStyle) {
            ((XSSFCellStyle)cellStyle).setLeftBorderColor(new XSSFColor(toRgbByte(borderColor)));
        } else {
            cellStyle.setLeftBorderColor(borderColor.getIndex());
        }
    }
    if (right) {
        cellStyle.setBorderRight(CellStyle.BORDER_THIN);
        if (cellStyle instanceof XSSFCellStyle) {
            ((XSSFCellStyle)cellStyle).setRightBorderColor(new XSSFColor(toRgbByte(borderColor)));
        } else {
            cellStyle.setRightBorderColor(borderColor.getIndex());
        }
    }
    if (bottom) {
        cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
        if (cellStyle instanceof XSSFCellStyle) {
            ((XSSFCellStyle)cellStyle).setBottomBorderColor(new XSSFColor(toRgbByte(borderColor)));
        } else {
            cellStyle.setBottomBorderColor(borderColor.getIndex());
        }
    }
    if (top) {
        cellStyle.setBorderTop(CellStyle.BORDER_THIN);
        if (cellStyle instanceof XSSFCellStyle) {
            ((XSSFCellStyle)cellStyle).setTopBorderColor(new XSSFColor(toRgbByte(borderColor)));
        } else {
            cellStyle.setTopBorderColor(borderColor.getIndex());
        }
    }
    return cellStyle;
}
项目:poi-on-android    文件:DocumentListActivity.java   
private void writeWorkbook() throws java.io.IOException {
    Workbook wb = new XSSFWorkbook();
    try {
        Sheet sheet = wb.createSheet("Sheet1");
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue("cell-1");
        cell = row.createCell(1);
        cell.setCellValue("cell-2");
        cell = row.createCell(2);
        cell.setCellValue("cell-3");

        XSSFCellStyle style = (XSSFCellStyle) wb.createCellStyle();
        style.setFillBackgroundColor(new XSSFColor(new org.apache.poi.java.awt.Color(1, 2, 3)));

        Hyperlink link = wb.getCreationHelper().createHyperlink(HyperlinkType.URL);
        link.setAddress("http://www.google.at");
        link.setLabel("Google");
        cell.setHyperlink(link);

        cell.setCellStyle(style);

        sheet.setPrintGridlines(true);

        OutputStream stream = openFileOutput("test.xlsx", Context.MODE_PRIVATE);
        try {
            wb.write(stream);
        } finally {
            stream.close();
        }
    } finally {
        wb.close();
    }
}
项目:meja    文件:PoiTest.java   
/**
 * Test converting color from Meja to POI color and back again does not
 * change the color value.
 *
 * This test checks the implementation for XSSF.
 */
@Test
public void testColorConversionXssf() {
    PoiWorkbook.PoiXssfWorkbook wb = (PoiWorkbook.PoiXssfWorkbook) PoiWorkbookFactory.instance().createXlsx();
    for (Color col : Color.values()) {
        XSSFColor poiColor = wb.getPoiColor(col);
        Color expected = col;
        Color actual = wb.getColor(poiColor, Color.BLACK);
        assertEquals(expected, actual);
    }
}
项目:owsi-core-parent    文件:AbstractExcelExport.java   
protected final void setStyleFillForegroundColor(CellStyle style, Map<Short, Color> colorRegistry, short color) {
    if (style instanceof XSSFCellStyle && colorRegistry.containsKey(color)) {
        ((XSSFCellStyle) style).setFillForegroundColor(new XSSFColor(colorRegistry.get(color)));
    } else {
        style.setFillForegroundColor(color);
    }
}