当前位置: 首页>>代码示例>>Java>>正文


Java HSSFPalette类代码示例

本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFPalette的典型用法代码示例。如果您正苦于以下问题:Java HSSFPalette类的具体用法?Java HSSFPalette怎么用?Java HSSFPalette使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HSSFPalette类属于org.apache.poi.hssf.usermodel包,在下文中一共展示了HSSFPalette类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createColor

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
/**
 * 创建颜色。
 * 
 * 写本方法的原因是:从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;
}
 
开发者ID:HY-ZhengWei,项目名称:hy.common.report,代码行数:40,代码来源:JavaToExcel.java

示例2: createHSSFCellStyle

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
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;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:24,代码来源:TitleStyleBuilder.java

示例3: replaceColorsPallete

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
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]
        );
    }
}
 
开发者ID:tecsinapse,项目名称:tecsinapse-data-io,代码行数:17,代码来源:WorkbookUtil.java

示例4: parseColor

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:chyxion,项目名称:table-to-xls,代码行数:24,代码来源:CssUtils.java

示例5: getHColour

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:eclipse,项目名称:birt,代码行数:31,代码来源:StyleManagerHUtils.java

示例6: correctFontColorIfBackground

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
@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;
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:28,代码来源:StyleManagerHUtils.java

示例7: getColorIndex

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
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());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:17,代码来源:ExcelUpdateCallback.java

示例8: buildHSSFColor

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
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;
}
 
开发者ID:youseries,项目名称:ureport,代码行数:14,代码来源:CellStyleContext.java

示例9: getPoiColor

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
@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());
}
 
开发者ID:xzel23,项目名称:meja,代码行数:9,代码来源:PoiWorkbook.java

示例10: getValueBlockStyle

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
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;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:11,代码来源:XlsSheetWriter.java

示例11: registerColor

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
/**
 * 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);
		}
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:21,代码来源:AbstractExcelExport.java

示例12: getHSSFColorString

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
/**
 * 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 "";
    }
}
 
开发者ID:excella-core,项目名称:excella-pdfexporter,代码行数:17,代码来源:ReportsTestUtil.java

示例13: createGlobalExportHeaderStyle

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
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;
}
 
开发者ID:sigmah-dev,项目名称:sigmah,代码行数:14,代码来源:ExcelUtils.java

示例14: createHeaderStyle

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
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;
}
 
开发者ID:sigmah-dev,项目名称:sigmah,代码行数:14,代码来源:ExcelUtils.java

示例15: createGroupStyle

import org.apache.poi.hssf.usermodel.HSSFPalette; //导入依赖的package包/类
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;
}
 
开发者ID:sigmah-dev,项目名称:sigmah,代码行数:14,代码来源:ExcelUtils.java


注:本文中的org.apache.poi.hssf.usermodel.HSSFPalette类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。