本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFColor类的典型用法代码示例。如果您正苦于以下问题:Java XSSFColor类的具体用法?Java XSSFColor怎么用?Java XSSFColor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XSSFColor类属于org.apache.poi.xssf.usermodel包,在下文中一共展示了XSSFColor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBackgroundColorXSSFCellStyle
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
/**
* @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;
}
示例2: createColorXSSFFont
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
/**
* @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;
}
示例3: getColor
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
/**
* 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;
}
示例4: styleColor
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
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]);
}
示例5: configFont
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
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());
}
}
}
示例6: createPoiFont
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
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;
}
示例7: setBorderStyle
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
@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();
}
}
示例8: getCellStyle
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
/**
* @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;
}
示例9: getXSSFColorString
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
/**
* 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();
}
示例10: getXSSFColorString
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
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();
}
示例11: getXSSFColorString
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
/**
* 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();
}
示例12: addColourToFont
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
@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);
}
}
}
示例13: addBackgroundColourToStyle
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
@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);
}
}
}
示例14: correctFontColorIfBackground
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
@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;
}
}
示例15: getRgbWithTint
import org.apache.poi.xssf.usermodel.XSSFColor; //导入依赖的package包/类
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;
}