Java 类org.apache.poi.hssf.usermodel.HSSFPalette 实例源码

项目:bdf2    文件:TitleStyleBuilder.java   
private HSSFCellStyle createHSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) {
    HSSFWorkbook workbook = (HSSFWorkbook) wb;
    HSSFPalette palette = workbook.getCustomPalette();

    palette.setColorAtIndex((short) 9, (byte) fontColor[0], (byte) fontColor[1], (byte) fontColor[2]);
    palette.setColorAtIndex((short) 10, (byte) bgColor[0], (byte) bgColor[1], (byte) bgColor[2]);

    HSSFFont titleFont = workbook.createFont();
    titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
    titleFont.setFontName("宋体");
    titleFont.setColor((short) 9);
    titleFont.setBold(true); 
    titleFont.setFontHeightInPoints((short) fontSize);

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

    return titleStyle;
}
项目:hy.common.report    文件:JavaToExcel.java   
/**
 * 创建颜色。
 * 
 * 写本方法的原因是:从2003版本的模板中复制单元格颜色时,会出现颜色失真的问题。
 * 
 * 但最终也没有解决。因为:当单元格的颜色设置为非标准颜色时,就会失真,但设置为标准颜色时,是正常的。
 * 
 * 也因为此,本方法与 i_ToCellStyle.setFillBackgroundColor(i_FromCellStyle.getFillBackgroundColor()); 的效果是相同的。
 * 
 * 本方法作为研究使用而保留下来,但不没有使用价值。
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-03-21
 * @version     v1.0
 *
 * @param i_FromColor
 * @param i_DataWorkbook
 * @return
 */
@Deprecated
public final static HSSFColor createColor(HSSFColor i_FromColor ,HSSFWorkbook i_DataWorkbook)
{
    short [] v_RGBHex    = i_FromColor.getTriplet();
    byte     v_ByteRed   = (byte)v_RGBHex[0];
    byte     v_ByteGreen = (byte)v_RGBHex[1];
    byte     v_ByteBlue  = (byte)v_RGBHex[2];

    HSSFPalette v_Palette   = i_DataWorkbook.getCustomPalette();
    HSSFColor   v_DataColor = v_Palette.findColor(v_ByteRed ,v_ByteGreen ,v_ByteBlue);

    if ( v_DataColor == null )
    {
        v_Palette.setColorAtIndex(i_FromColor.getIndex() ,v_ByteRed ,v_ByteGreen ,v_ByteBlue);

        return v_Palette.getColor(i_FromColor.getIndex());
    }

    return  v_DataColor;
}
项目:tecsinapse-data-io    文件:WorkbookUtil.java   
private void replaceColorsPallete(Map<HSSFColor, HSSFColor> colorsReplaceMap, Workbook wb) {
    if (! (wb instanceof HSSFWorkbook)) {
        return;
    }

    HSSFWorkbook hssfWb = (HSSFWorkbook) wb;
    final HSSFPalette customPalette = hssfWb.getCustomPalette();
    for (Entry<HSSFColor, HSSFColor> e : colorsReplaceMap.entrySet()) {
        short[] rgb = e.getValue().getTriplet();
        customPalette.setColorAtIndex(e.getKey().getIndex(),
                (byte)rgb[0],
                (byte)rgb[1],
                (byte)rgb[2]
        );
    }
}
项目:table-to-xls    文件:CssUtils.java   
/**
 * parse color
 * @param workBook work book
 * @param color string color
 * @return HSSFColor 
 */
public static HSSFColor parseColor(HSSFWorkbook workBook, String color) {
    HSSFColor poiColor = null;
    if (StringUtils.isNotBlank(color)) {
        Color awtColor = Color.decode(color);
        if (awtColor != null) {
            int r = awtColor.getRed();
            int g = awtColor.getGreen();
            int b = awtColor.getBlue();
            HSSFPalette palette = workBook.getCustomPalette();
            poiColor = palette.findColor((byte) r, (byte) g, (byte) b);
            if (poiColor == null) {
                poiColor = palette.findSimilarColor(r, g, b);
            }
        }
    }
    return poiColor;
}
项目:birt    文件:StyleManagerHUtils.java   
/**
 * Get an HSSFPalette index for a workbook that closely approximates the passed in colour.
 * @param workbook
 * The workbook for which the colour is being sought.
 * @param colour
 * The colour, in the form "rgb(<i>r</i>, <i>g</i>, <i>b</i>)".
 * @return
 * The index into the HSSFPallete for the workbook for a colour that approximates the passed in colour.
 */
private short getHColour( HSSFWorkbook workbook, String colour ) {
    int[] rgbInt = ColorUtil.getRGBs(colour);
    if( rgbInt == null ) {
        return 0;
    }

    byte[] rgbByte = new byte[] { (byte)rgbInt[0], (byte)rgbInt[1], (byte)rgbInt[2] };
    HSSFPalette palette = workbook.getCustomPalette();

    HSSFColor result = palette.findColor(rgbByte[0], rgbByte[1], rgbByte[2]);
    if( result == null) {
        if( paletteIndex > minPaletteIndex ) {
            --paletteIndex;
            palette.setColorAtIndex(paletteIndex, rgbByte[0], rgbByte[1], rgbByte[2]);
            return paletteIndex;
        } else {
            result = palette.findSimilarColor(rgbByte[0], rgbByte[1], rgbByte[2]);
        }
    }
    return result.getIndex();
}
项目:birt    文件:StyleManagerHUtils.java   
@Override
public Font correctFontColorIfBackground(FontManager fm, Workbook wb, BirtStyle birtStyle, Font font) {
    HSSFPalette palette = ((HSSFWorkbook)wb).getCustomPalette();        

    CSSValue bgColour = birtStyle.getProperty( StyleConstants.STYLE_BACKGROUND_COLOR );
    int bgRgb[] = parseColour( bgColour == null ? null : bgColour.getCssText(), "white" );

    short fgRgb[] = HSSFColor.BLACK.triplet;
    if( ( font != null ) && ( font.getColor() != Short.MAX_VALUE ) ) {
        fgRgb = palette.getColor(font.getColor()).getTriplet();
    }
    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;
    }
}
项目:metamodel    文件:ExcelUpdateCallback.java   
public short getColorIndex(Color color) {
    Workbook workbook = getWorkbook(true);
    if (workbook instanceof HSSFWorkbook) {
        HSSFPalette palette = ((HSSFWorkbook) workbook).getCustomPalette();
        byte r = toRgb(color.getRed());
        byte g = toRgb(color.getGreen());
        byte b = toRgb(color.getBlue());

        HSSFColor index = palette.findColor(r, g, b);
        if (index == null) {
            index = palette.findSimilarColor(r, g, b);
        }
        return index.getIndex();
    }
    throw new IllegalStateException("Unexpected workbook type: " + workbook.getClass());
}
项目:ureport    文件:CellStyleContext.java   
private HSSFColor buildHSSFColor(HSSFWorkbook wb,String colorStr){
    String[] color=colorStr.split(",");
    HSSFPalette palette=wb.getCustomPalette();
    byte r=BigInteger.valueOf(Integer.valueOf(color[0])).byteValue();
    byte g=BigInteger.valueOf(Integer.valueOf(color[1])).byteValue();
    byte b=BigInteger.valueOf(Integer.valueOf(color[2])).byteValue();
    HSSFColor targetColor=palette.findColor(r,g,b);
    if(targetColor==null){
        palette.setColorAtIndex(HSSFColorPredefined.LAVENDER.getIndex(), r, g,b);
        targetColor=palette.getColor(HSSFColorPredefined.LAVENDER.getIndex());
    }
    return targetColor;
}
项目:meja    文件:PoiWorkbook.java   
@Override
public HSSFColor getPoiColor(Color color) {
    if (color == null) {
        return null;
    }
    HSSFPalette palette = ((HSSFWorkbook) poiWorkbook).getCustomPalette();
    return palette.findSimilarColor(color.r(), color.g(), color.b());
}
项目:FinanceAnalytics    文件:XlsSheetWriter.java   
private CellStyle getValueBlockStyle() {
  CellStyle style = _workbook.createCellStyle();
  Font font = _workbook.createFont();
  HSSFPalette palette = _workbook.getCustomPalette();
  palette.setColorAtIndex(HSSFColor.BLUE_GREY.index, (byte) 238, (byte) 238, (byte) 238);
  style.setFillForegroundColor(HSSFColor.BLUE_GREY.index);
  style.setFillPattern(CellStyle.SOLID_FOREGROUND);
  style.setFont(font);
  return style;
}
项目:owsi-core-parent    文件:AbstractExcelExport.java   
/**
 * Enregistre une couleur dans le registre des couleurs
 * 
 * @param index index de la couleur
 * @param hexaColor code hexadécimal de la couleur
 */
protected final void registerColor(short index, String hexaColor) {
    if (hexaColor != null && hexaColor.matches("#[0-9a-fA-F]{6}")) {
        int red = Integer.parseInt(hexaColor.substring(1, 3), 16);
        int green = Integer.parseInt(hexaColor.substring(3, 5), 16);
        int blue = Integer.parseInt(hexaColor.substring(5, 7), 16);

        colorRegistry.put(index, new Color(red, green, blue));

        if (workbook instanceof HSSFWorkbook) {
            HSSFPalette palette = ((HSSFWorkbook) workbook).getCustomPalette();
            palette.setColorAtIndex(index, (byte) red, (byte) green, (byte) blue);
        }
    }
}
项目:excella-pdfexporter    文件:ReportsTestUtil.java   
/**
 * HSSF色の文字列表現を取得する
 * 
 * @param workbook ブック
 * @param index 色インデックス
 * @return HSSF色の文字列表現
 */
private static String getHSSFColorString( HSSFWorkbook workbook, short index) {
    HSSFPalette palette = workbook.getCustomPalette();
    if ( palette.getColor( index) != null) {
        HSSFColor color = palette.getColor( index);
        return color.getHexString();
    } else {
        return "";
    }
}
项目:sigmah    文件:ExcelUtils.java   
private CellStyle createGlobalExportHeaderStyle(HSSFWorkbook wb) {
    final CellStyle style = createBorderedStyle(wb);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

    final HSSFPalette palette = wb.getCustomPalette();
    palette.setColorAtIndex(HSSFColor.GREY_25_PERCENT.index, ExportConstants.GRAY_5_RGB[0], ExportConstants.GRAY_5_RGB[1], ExportConstants.GRAY_5_RGB[2]);
    style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(getItalicFont(wb, (short) 10));
    style.setWrapText(true);
    style.setIndention((short) 1);
    return style;
}
项目:sigmah    文件:ExcelUtils.java   
private CellStyle createHeaderStyle(HSSFWorkbook wb) {
    final CellStyle style = createBorderedStyle(wb);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

    HSSFPalette palette = wb.getCustomPalette();
    palette.setColorAtIndex(HSSFColor.GREY_25_PERCENT.index, ExportConstants.GRAY_10_RGB[0], ExportConstants.GRAY_10_RGB[1], ExportConstants.GRAY_10_RGB[2]);
    style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(getBoldFont(wb, (short) 10));
    style.setWrapText(true);
    return style;
}
项目:sigmah    文件:ExcelUtils.java   
private CellStyle createGroupStyle(HSSFWorkbook wb) {
    final CellStyle style = createBorderedStyle(wb);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

    HSSFPalette palette = wb.getCustomPalette();
    palette.setColorAtIndex(HSSFColor.BROWN.index, ExportConstants.LIGHTORANGE_RGB[0], ExportConstants.LIGHTORANGE_RGB[1], ExportConstants.LIGHTORANGE_RGB[2]);

    style.setFillForegroundColor(HSSFColor.BROWN.index);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(getItalicFont(wb, (short) 10));
    style.setWrapText(true);
    return style;
}
项目:excella-core    文件:TestUtil.java   
private static String getHSSFColorString( HSSFWorkbook workbook, short index) {
    HSSFPalette palette = workbook.getCustomPalette();
    if ( palette.getColor( index) != null) {
        HSSFColor color = palette.getColor( index);
        return color.getHexString();
    } else {
        return "";
    }
}
项目:excella-reports    文件:ReportsTestUtil.java   
/**
 * HSSF色の文字列表現を取得する
 * 
 * @param workbook ブック
 * @param index 色インデックス
 * @return HSSF色の文字列表現
 */
private static String getHSSFColorString( HSSFWorkbook workbook, short index) {
    HSSFPalette palette = workbook.getCustomPalette();
    if ( palette.getColor( index) != null) {
        HSSFColor color = palette.getColor( index);
        return color.getHexString();
    } else {
        return "";
    }
}
项目:netxilia    文件:PoiUtils.java   
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());
    }
    // 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;
}
项目:BBSSDK-for-Android    文件:OfficeConverter.java   
private void xlsToHtml() throws Throwable {
    FileOutputStream output = new FileOutputStream(new File(htmlPath));
    StringBuffer htmlHeaderSB = new StringBuffer();
    htmlHeaderSB.append("<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' "
            + "xmlns='http://www.w3.org/TR/REC-html40'>");
    htmlHeaderSB.append("<head><meta http-equiv=Content-Type content='text/html; charset=utf-8'><meta name=ProgId content=Excel.Sheet>"
            + "</head><body>");
    output.write(htmlHeaderSB.toString().getBytes());
    HSSFSheet sheet;
    HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filePath)); // 获整个Excel
    for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
        if (workbook.getSheetAt(sheetIndex) != null) {
            sheet = workbook.getSheetAt(sheetIndex);// 获得不为空的这个sheet
            if (sheet != null) {
                int firstRowNum = sheet.getFirstRowNum(); // 第一行
                int lastRowNum = sheet.getLastRowNum(); // 最后一行
                // 构造Table
                output.write(("<table width=\"100%\" style=\"border:1px solid #000;border-width:1px 0 0 1px;margin:2px 0 2px 0;"
                        + "border-collapse:collapse;\">").getBytes());
                for (int rowNum = firstRowNum; rowNum <= lastRowNum; rowNum++) {
                    if (sheet.getRow(rowNum) != null) {// 如果行不为空,
                        HSSFRow row = sheet.getRow(rowNum);
                        short firstCellNum = row.getFirstCellNum(); // 该行的第一个单元格
                        short lastCellNum = row.getLastCellNum(); // 该行的最后一个单元格
                        int height = (int) (row.getHeight() / 15.625); // 行的高度
                        output.write(("<tr height=\"" + height + "\" style=\"border:1px solid #000;border-width:0 1px 1px 0;"
                                + "margin:2px 0 2px 0;\">").getBytes());
                        for (short cellNum = firstCellNum; cellNum <= lastCellNum; cellNum++) { // 循环该行的每一个单元格
                            HSSFCell cell = row.getCell(cellNum);
                            if (cell != null) {
                                if (cell.getCellType() != HSSFCell.CELL_TYPE_BLANK) {
                                    StringBuffer tdStyle = new StringBuffer("<td style=\"border:1px solid #000; border-width:0 1px 1px 0;"
                                            + "margin:2px 0 2px 0; ");
                                    HSSFCellStyle cellStyle = cell.getCellStyle();
                                    HSSFPalette palette = workbook.getCustomPalette(); // 类HSSFPalette用于求颜色的国际标准形式
                                    HSSFColor hColor = palette.getColor(cellStyle.getFillForegroundColor());
                                    HSSFColor hColor2 = palette.getColor(cellStyle.getFont(workbook).getColor());
                                    String bgColor = convertToStardColor(hColor);// 背景颜色
                                    short boldWeight = cellStyle.getFont(workbook).getBoldweight(); // 字体粗细
                                    short fontHeight = (short) (cellStyle.getFont(workbook).getFontHeight() / 2); // 字体大小
                                    String fontColor = convertToStardColor(hColor2); // 字体颜色
                                    if (bgColor != null && !"".equals(bgColor.trim())) {
                                        tdStyle.append(" background-color:");
                                        tdStyle.append(bgColor);
                                        tdStyle.append("; ");
                                    }
                                    if (fontColor != null && !"".equals(fontColor.trim())) {
                                        tdStyle.append(" color:");
                                        tdStyle.append(fontColor);
                                        tdStyle.append("; ");
                                    }
                                    tdStyle.append(" font-weight:");
                                    tdStyle.append(boldWeight);
                                    tdStyle.append("; ");
                                    tdStyle.append(" font-size: ");
                                    tdStyle.append(fontHeight);
                                    tdStyle.append("%;");
                                    output.write((tdStyle + "\"").getBytes());

                                    int width = (int) (sheet.getColumnWidth(cellNum) / 35.7); //
                                    int cellRegionCol = getMergerCellRegionCol(sheet, rowNum, cellNum); // 合并的列(solspan)
                                    int cellRegionRow = getMergerCellRegionRow(sheet, rowNum, cellNum);// 合并的行(rowspan)
                                    String align = convertAlignToHtml(cellStyle.getAlignment()); //
                                    String vAlign = convertVerticalAlignToHtml(cellStyle.getVerticalAlignment());

                                    output.write((" align=\"" + align + "\" valign=\"" + vAlign + "\" width=\"" + width + "\" ").getBytes());
                                    output.write((" colspan=\"" + cellRegionCol + "\" rowspan=\"" + cellRegionRow + "\"").getBytes());
                                    output.write((">" + getCellValue(cell) + "</td>").getBytes());
                                }
                            }
                        }
                        output.write("</tr>".getBytes());
                    }
                }
                output.write(("</table>").getBytes());
            }
        }
    }
    output.write(("</body></html>").getBytes());
    output.close();
}
项目:bdf2    文件:GridStyleBuilder.java   
private Map<String, CellStyle> createHSSFCellStyles(Workbook wb, int[] contextBgColor, int[] contextFontColor, int contextFontSize, int contextFontAlign, int[] headerBgColor,
        int[] headerFontColor, int headerFontSize, int headerAlign) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

    HSSFWorkbook workbook = (HSSFWorkbook) wb;
    HSSFPalette palette = workbook.getCustomPalette();
    palette.setColorAtIndex((short) 11, (byte) contextBgColor[0], (byte) contextBgColor[1], (byte) contextBgColor[2]);
    palette.setColorAtIndex((short) 12, (byte) contextFontColor[0], (byte) contextFontColor[1], (byte) contextFontColor[2]);
    palette.setColorAtIndex((short) 13, (byte) headerBgColor[0], (byte) headerBgColor[1], (byte) headerBgColor[2]);
    palette.setColorAtIndex((short) 14, (byte) headerFontColor[0], (byte) headerFontColor[1], (byte) headerFontColor[2]);

    HSSFFont headerFont = workbook.createFont();
    headerFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
    headerFont.setFontName("宋体");
    headerFont.setColor((short) 14);
    headerFont.setBold(true);
    headerFont.setFontHeightInPoints((short) headerFontSize);
    CellStyle headerStyle = this.createBorderCellStyle(workbook, true);

    headerStyle.setFont(headerFont);
    headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    headerStyle.setFillForegroundColor((short) 13);
    this.setCellStyleAligment(headerStyle, headerAlign);
    headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    styles.put(GridStyleType.headerStyle.name(), headerStyle);

    HSSFFont dataFont = workbook.createFont();
    dataFont.setColor((short) 12);
    dataFont.setFontHeightInPoints((short) contextFontSize);
    dataFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
    dataFont.setFontName("宋体");

    CellStyle dataAlignLeftStyle = this.createBorderCellStyle(workbook, true);
    dataAlignLeftStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    dataAlignLeftStyle.setFillForegroundColor((short) 11);
    dataAlignLeftStyle.setFont(dataFont);
    dataAlignLeftStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    dataAlignLeftStyle.setWrapText(true);
    dataAlignLeftStyle.setAlignment(HorizontalAlignment.LEFT);
    styles.put(GridStyleType.dataAlignLeftStyle.name(), dataAlignLeftStyle);

    CellStyle dataAlignCenterStyle = this.createBorderCellStyle(workbook, true);
    dataAlignCenterStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    dataAlignCenterStyle.setFillForegroundColor((short) 11);
    dataAlignCenterStyle.setFont(dataFont);
    dataAlignCenterStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    dataAlignCenterStyle.setWrapText(true);
    dataAlignCenterStyle.setAlignment(HorizontalAlignment.CENTER);
    styles.put(GridStyleType.dataAlignCenterStyle.name(), dataAlignCenterStyle);

    CellStyle dataAlignRightStyle = this.createBorderCellStyle(workbook, true);
    dataAlignRightStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    dataAlignRightStyle.setFillForegroundColor((short) 11);
    dataAlignRightStyle.setFont(dataFont);
    dataAlignRightStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    dataAlignRightStyle.setWrapText(true);
    dataAlignRightStyle.setAlignment(HorizontalAlignment.RIGHT);
    styles.put(GridStyleType.dataAlignRightStyle.name(), dataAlignRightStyle);

    CellStyle dateStyle = this.createBorderCellStyle(workbook, true);
    CreationHelper helper = workbook.getCreationHelper();
    dateStyle.setDataFormat(helper.createDataFormat().getFormat("m/d/yy h:mm"));
    dateStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    dateStyle.setFillForegroundColor((short) 11);
    dateStyle.setFont(dataFont);
    dateStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    this.setCellStyleAligment(dateStyle, contextFontAlign);
    styles.put(GridStyleType.dateStyle.name(), dateStyle);

    return styles;
}
项目:FinanceAnalytics    文件:XlsSheetWriter.java   
private CellStyle getKeyBlockStyle() {
  CellStyle style = _workbook.createCellStyle();
  Font font = _workbook.createFont();
  font.setColor(HSSFColor.WHITE.index);
  HSSFPalette palette = _workbook.getCustomPalette();
  palette.setColorAtIndex(HSSFColor.BLUE.index, (byte) 3, (byte) 60, (byte) 90);
  style.setFillForegroundColor(HSSFColor.BLUE.index);
  style.setFillPattern(CellStyle.SOLID_FOREGROUND);
  style.setFont(font);
  return style;
}
项目:FinanceAnalytics    文件:XlsSheetWriter.java   
private CellStyle getAxisStyle() {
  CellStyle style = _workbook.createCellStyle();
  Font font = _workbook.createFont();
  font.setColor(HSSFColor.WHITE.index);
  HSSFPalette palette = _workbook.getCustomPalette();
  palette.setColorAtIndex(HSSFColor.GREY_50_PERCENT.index, (byte) 68, (byte) 68, (byte) 68);
  style.setFillForegroundColor(HSSFColor.GREY_50_PERCENT.index);
  style.setFillPattern(CellStyle.SOLID_FOREGROUND);
  style.setFont(font);
  return style;
}
项目:embulk-parser-poi_excel    文件:PoiExcelColorVisitor.java   
public static Color getHssfColor(Workbook workbook, short colorIndex) {
    HSSFWorkbook book = (HSSFWorkbook) workbook;
    HSSFPalette palette = book.getCustomPalette();
    HSSFColor color = palette.getColor(colorIndex);
    return color;
}
项目:netxilia    文件:ExcelImportService.java   
private ICellCommand copyCell(Cell poiCell, CellReference cellReference, HSSFPalette palette,
        NetxiliaStyleResolver styleResolver) throws FormulaParsingException {

    CellStyle poiStyle = poiCell.getCellStyle();
    Styles styles = PoiUtils.poiStyle2Netxilia(poiStyle,
            poiCell.getSheet().getWorkbook().getFontAt(poiStyle.getFontIndex()), palette, styleResolver);

    IGenericValue value = null;
    Formula formula = null;

    // log.info("CELL TYPE:" + cellReference + " type:" + poiCell.getCellType() + " "
    // + (poiCell.getCellType() == Cell.CELL_TYPE_FORMULA ? poiCell.getCellFormula() : "no"));
    switch (poiCell.getCellType()) {
    // TODO translate errors

    case Cell.CELL_TYPE_STRING:
        value = new StringValue(poiCell.getStringCellValue());
        break;
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(poiCell)) {
            DateTime dt = new DateTime(poiCell.getDateCellValue());
            // TODO decide whether is date or time
            if (dt.isBefore(EXCEL_START)) {
                value = new DateValue(dt.toLocalTime());
            } else if (dt.getMillisOfDay() == 0) {
                value = new DateValue(dt.toLocalDate());
            } else {
                value = new DateValue(dt.toLocalDateTime());
            }
        } else {
            value = new NumberValue(poiCell.getNumericCellValue());
        }
        break;
    case Cell.CELL_TYPE_BOOLEAN:
        value = new BooleanValue(poiCell.getBooleanCellValue());
        break;
    case Cell.CELL_TYPE_FORMULA:
        if (poiCell.getCellFormula() != null) {
            formula = formulaParser.parseFormula(new Formula("=" + poiCell.getCellFormula()));
        }
        break;
    }

    if ((styles == null || styles.getItems().isEmpty()) && formula == null
            && (value == null || value.equals(GenericValueUtils.EMTPY_STRING))) {
        return null;
    }
    return CellCommands.cell(new AreaReference(cellReference), value, formula, styles);
}