本文整理汇总了Java中org.apache.poi.ss.usermodel.Color类的典型用法代码示例。如果您正苦于以下问题:Java Color类的具体用法?Java Color怎么用?Java Color使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Color类属于org.apache.poi.ss.usermodel包,在下文中一共展示了Color类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAttributeValue
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
protected final Object getAttributeValue(Column column, Cell cell, A source, String key) {
Map<String, AttributeSupplier<A>> map = getAttributeSupplierMap();
AttributeSupplier<A> supplier = map.get(key.toLowerCase());
if (supplier == null) {
throw new UnsupportedOperationException(MessageFormat.format(
"unsupported attribute name={0}, choose in {1}", key, new TreeSet<>(map.keySet())));
}
Object value = supplier.get(column, cell, source);
if (value instanceof Color) {
int rgb = PoiExcelColorVisitor.getRGB((Color) value);
if (rgb < 0) {
return null;
}
if (column.getType() instanceof StringType) {
value = String.format("%06x", rgb);
} else {
value = (long) rgb;
}
}
return value;
}
示例2: styleColor
import org.apache.poi.ss.usermodel.Color; //导入依赖的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]);
}
示例3: retrieveFont
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
/**
* Retrieve a <code>Font</code> from the cache with the given
* properties.
* @param fontBoldweight The font boldweight.
* @param fontItalic Whether the font is italic.
* @param fontColor The font color.
* @param fontName The font name.
* @param fontHeightInPoints The font height in points.
* @param fontUnderline The font underline.
* @param fontStrikeout Whether the font is in strikeout.
* @param fontCharset The font charset.
* @param fontTypeOffset The font type offset.
* @return A <code>Font</code> that matches all given properties, or
* <code>null</code> if it doesn't exist.
*/
public Font retrieveFont(short fontBoldweight, boolean fontItalic, Color fontColor, String fontName,
short fontHeightInPoints, byte fontUnderline, boolean fontStrikeout, int fontCharset, short fontTypeOffset)
{
String representation = getRepresentation(fontBoldweight, fontItalic, fontColor, fontName, fontHeightInPoints,
fontUnderline, fontStrikeout, fontCharset, fontTypeOffset
);
Font f = myFontMap.get(representation);
if (DEBUG)
{
if (f != null)
System.err.println("FCache hit : " + representation);
else
System.err.println("FCache miss! : " + representation);
}
return f;
}
示例4: getRepresentation
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
/**
* Gets the string representation of the given <code>Font</code>.
* @param f A <code>Font</code>.
* @return The string representation.
*/
private String getRepresentation(Font f)
{
// Colors that need an instanceof check
Color fontColor;
if (f instanceof HSSFFont)
{
HSSFFont hf = (HSSFFont) f;
fontColor = hf.getHSSFColor((HSSFWorkbook) myWorkbook);
}
else if (f instanceof XSSFFont)
{
XSSFFont xf = (XSSFFont) f;
fontColor = xf.getXSSFColor();
}
else
throw new IllegalArgumentException("Bad Font type: " + f.getClass().getName());
return getRepresentation(f.getBoldweight(), f.getItalic(), fontColor, f.getFontName(),
f.getFontHeightInPoints(), f.getUnderline(), f.getStrikeout(), f.getCharSet(), f.getTypeOffset());
}
示例5: getColorHexString
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
/**
* Get the hex string that represents the <code>Color</code>.
* @param color A POI <code>Color</code>.
* @return The hex string that represents the <code>Color</code>.
* @since 0.5.0
*/
public static String getColorHexString(Color color)
{
if (color instanceof HSSFColor)
{
HSSFColor hssfColor = (HSSFColor) color;
return getHSSFColorHexString(hssfColor);
}
else if (color == null)
{
return "null";
}
else
{
throw new IllegalArgumentException("Unexpected type of Color: " + color.getClass().getName());
}
}
示例6: createFont
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
/**
* Creates a new <code>Font</code> for the given <code>Workbook</code>,
* with the given attributes. Moved from <code>StyleTag</code> here for
* 0.5.0.
* @param workbook A <code>Workbook</code>.
* @param fontBoldweight A <code>short</code> boldweight constant.
* @param fontItalic Whether the text is italic.
* @param fontColor A color <code>Color</code> opbject.
* @param fontName A font name.
* @param fontHeightInPoints A <code>short</code> font height in points.
* @param fontUnderline A <code>byte</code> underline constant.
* @param fontStrikeout Whether the font is strikeout.
* @param fontCharset An <code>int</code> charset constant.
* @param fontTypeOffset A <code>short</code> type offset constant.
* @return A new <code>Font</code>.
*/
public static Font createFont(Workbook workbook, short fontBoldweight, boolean fontItalic, Color fontColor, String fontName, short fontHeightInPoints, byte fontUnderline,
boolean fontStrikeout, int fontCharset, short fontTypeOffset)
{
if (DEBUG)
{
System.err.println("createFont: " + fontBoldweight + "," + fontItalic + "," +
((fontColor == null) ? "null" :fontColor.toString()
// (fontColor instanceof HSSFColor) ? fontColor.toString() :
// ((XSSFColor) fontColor).getCTColor().toString()
) + "," + fontName + "," +
fontHeightInPoints + "," + fontUnderline + "," + fontStrikeout + "," + fontCharset + "," + fontTypeOffset);
}
Font f = workbook.createFont();
f.setBoldweight(fontBoldweight);
f.setItalic(fontItalic);
f.setFontName(fontName);
f.setFontHeightInPoints(fontHeightInPoints);
f.setUnderline(fontUnderline);
f.setStrikeout(fontStrikeout);
f.setCharSet(fontCharset);
f.setTypeOffset(fontTypeOffset);
// Color type check.
if (fontColor instanceof HSSFColor)
{
f.setColor(((HSSFColor) fontColor).getIndex());
}
return f;
}
示例7: getColor
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
private Color getColor(Font font) {
if (helper instanceof HSSFHtmlHelper) {
return ((HSSFWorkbook) sheet.getWorkbook()).getCustomPalette()
.getColor(font.getColor());
} else {
return ((XSSFFont) font).getXSSFColor();
}
}
示例8: styleColor
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
public void styleColor(Formatter out, String attr, Color color) {
if (color == null) {
return;
}
HSSFColor hSSFColor = (HSSFColor) color;
short[] rgb = hSSFColor.getTriplet();
out.format(" %s: #%02x%02x%02x; %n", attr, rgb[0], rgb[1], rgb[2]);
}
示例9: visitCellColor
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
public void visitCellColor(Column column, Color color, CellVisitor visitor) {
int rgb = getRGB(color);
if (rgb < 0) {
PageBuilder pageBuilder = visitorValue.getPageBuilder();
pageBuilder.setNull(column);
return;
}
if (column.getType() instanceof StringType) {
String s = String.format("%06x", rgb);
visitor.visitCellValueString(column, color, s);
} else {
visitor.visitValueLong(column, color, rgb);
}
}
示例10: getRGB
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
public static int getRGB(Color color) {
if (color == null) {
return -1;
}
int[] rgb = new int[3];
if (color instanceof HSSFColor) {
HSSFColor hssf = (HSSFColor) color;
short[] s = hssf.getTriplet();
rgb[0] = s[0] & 0xff;
rgb[1] = s[1] & 0xff;
rgb[2] = s[2] & 0xff;
} else if (color instanceof XSSFColor) {
XSSFColor xssf = (XSSFColor) color;
byte[] b = xssf.getRGB();
if (b == null) {
return -1;
}
rgb[0] = b[0] & 0xff;
rgb[1] = b[1] & 0xff;
rgb[2] = b[2] & 0xff;
} else {
throw new IllegalStateException(MessageFormat.format("unsupported POI color={0}", color));
}
return (rgb[0] << 16) | (rgb[1] << 8) | rgb[2];
}
示例11: getHssfColor
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
public Color getHssfColor(short colorIndex) {
HSSFWorkbook book = (HSSFWorkbook) visitorValue.getSheet().getWorkbook();
return getHssfColor(book, colorIndex);
}
示例12: removeBorders
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
/**
* Remove all borders from all cells in the region described by the left,
* right, top, and bottom bounds.
* @param sheet The <code>Sheet</code>.
* @param left The 0-based index indicating the left-most part of the region.
* @param right The 0-based index indicating the right-most part of the region.
* @param top The 0-based index indicating the top-most part of the region.
* @param bottom The 0-based index indicating the bottom-most part of the region.
*/
private void removeBorders(Sheet sheet, int left, int right, int top, int bottom)
{
if (DEBUG)
System.err.println("removeBorders: " + left + ", " + right + ", " + top + ", " + bottom);
CellStyleCache csCache = getWorkbookContext().getCellStyleCache();
for (int r = top; r <= bottom; r++)
{
Row row = sheet.getRow(r);
for (int c = left; c <= right; c++)
{
Cell cell = row.getCell(c);
if (cell != null)
{
CellStyle cs = cell.getCellStyle();
Font f = sheet.getWorkbook().getFontAt(cs.getFontIndex());
Color fontColor;
if (cs instanceof HSSFCellStyle)
{
fontColor = ExcelColor.getHssfColorByIndex(f.getColor());
}
else
{
fontColor = ((XSSFFont) f).getXSSFColor();
}
// At this point, we have all of the desired CellStyle and Font
// characteristics. Find a CellStyle if it exists.
CellStyle foundStyle = csCache.retrieveCellStyle(f.getBoldweight(), f.getItalic(), fontColor,
f.getFontName(), f.getFontHeightInPoints(), cs.getAlignment(), CellStyle.BORDER_NONE,
CellStyle.BORDER_NONE, CellStyle.BORDER_NONE, CellStyle.BORDER_NONE, cs.getDataFormatString(),
f.getUnderline(), f.getStrikeout(), cs.getWrapText(), cs.getFillBackgroundColorColor(),
cs.getFillForegroundColorColor(), cs.getFillPattern(), cs.getVerticalAlignment(), cs.getIndention(),
cs.getRotation(), null, null, null, null,
f.getCharSet(), f.getTypeOffset(), cs.getLocked(), cs.getHidden());
if (foundStyle == null)
{
foundStyle = SheetUtil.createCellStyle(sheet.getWorkbook(), cs.getAlignment(), CellStyle.BORDER_NONE,
CellStyle.BORDER_NONE, CellStyle.BORDER_NONE, CellStyle.BORDER_NONE, cs.getDataFormatString(),
cs.getWrapText(), cs.getFillBackgroundColorColor(), cs.getFillForegroundColorColor(),
cs.getFillPattern(), cs.getVerticalAlignment(), cs.getIndention(), cs.getRotation(),
null, null, null, null, cs.getLocked(), cs.getHidden());
foundStyle.setFont(f);
}
cell.setCellStyle(foundStyle);
}
}
}
}
示例13: putBackBorders
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
/**
* Puts back borders for the newly sized merged region.
* @param sheet The <code>Sheet</code>.
* @param left The 0-based index indicating the left-most part of the region.
* @param right The 0-based index indicating the right-most part of the region.
* @param top The 0-based index indicating the top-most part of the region.
* @param bottom The 0-based index indicating the bottom-most part of the region.
* @param borderLeft The left border type.
* @param borderRight The right border type.
* @param borderTop The top border type.
* @param borderBottom The bottom border type.
* @param borderLeftColor The left border color.
* @param borderRightColor The right border color.
* @param borderTopColor The top border color.
* @param borderBottomColor The bottom border color.
*/
private void putBackBorders(Sheet sheet, int left, int right, int top, int bottom,
short borderLeft, short borderRight, short borderTop, short borderBottom,
Color borderLeftColor, Color borderRightColor, Color borderTopColor, Color borderBottomColor)
{
if (DEBUG)
System.err.println("putBackBorders: " + left + ", " + right + ", " + top + ", " + bottom);
CellStyleCache csCache = getWorkbookContext().getCellStyleCache();
for (int r = top; r <= bottom; r++)
{
Row row = sheet.getRow(r);
if (row == null)
row = sheet.createRow(r);
for (int c = left; c <= right; c++)
{
Cell cell = row.getCell(c);
if (cell == null)
cell = row.createCell(c);
CellStyle cs = cell.getCellStyle();
Font f = sheet.getWorkbook().getFontAt(cs.getFontIndex());
Color fontColor;
if (cs instanceof HSSFCellStyle)
{
fontColor = ExcelColor.getHssfColorByIndex(f.getColor());
}
else
{
fontColor = ((XSSFFont) f).getXSSFColor();
}
short newBorderBottom = (r == bottom) ? borderBottom : CellStyle.BORDER_NONE;
short newBorderLeft = (c == left) ? borderLeft : CellStyle.BORDER_NONE;
short newBorderRight = (c == right) ? borderRight : CellStyle.BORDER_NONE;
short newBorderTop = (r == top) ? borderTop : CellStyle.BORDER_NONE;
Color newBorderBottomColor = (r == bottom) ? borderBottomColor : null;
Color newBorderLeftColor = (c == left) ? borderLeftColor : null;
Color newBorderRightColor = (c == right) ? borderRightColor : null;
Color newBorderTopColor = (r == top) ? borderTopColor : null;
// At this point, we have all of the desired CellStyle and Font
// characteristics. Find a CellStyle if it exists.
CellStyle foundStyle = csCache.retrieveCellStyle(f.getBoldweight(), f.getItalic(), fontColor,
f.getFontName(), f.getFontHeightInPoints(), cs.getAlignment(),
newBorderBottom, newBorderLeft, newBorderRight, newBorderTop, cs.getDataFormatString(),
f.getUnderline(), f.getStrikeout(), cs.getWrapText(), cs.getFillBackgroundColorColor(),
cs.getFillForegroundColorColor(), cs.getFillPattern(), cs.getVerticalAlignment(), cs.getIndention(),
cs.getRotation(), newBorderBottomColor, newBorderLeftColor, newBorderRightColor, newBorderTopColor,
f.getCharSet(), f.getTypeOffset(), cs.getLocked(), cs.getHidden());
if (foundStyle == null)
{
foundStyle = SheetUtil.createCellStyle(sheet.getWorkbook(), cs.getAlignment(), newBorderBottom,
newBorderLeft, newBorderRight, newBorderTop, cs.getDataFormatString(),
cs.getWrapText(), cs.getFillBackgroundColorColor(), cs.getFillForegroundColorColor(),
cs.getFillPattern(), cs.getVerticalAlignment(), cs.getIndention(), cs.getRotation(),
newBorderBottomColor, newBorderLeftColor, newBorderRightColor, newBorderTopColor,
cs.getLocked(), cs.getHidden());
foundStyle.setFont(f);
}
cell.setCellStyle(foundStyle);
}
}
}
示例14: retrieveCellStyle
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
/**
* Retrieve a <code>CellStyle</code> from the cache with the given
* properties.
* @param fontBoldweight The font boldweight.
* @param fontItalic Whether the font is italic.
* @param fontColor The font color.
* @param fontName The font name.
* @param fontHeightInPoints The font height in points.
* @param alignment The horizontal alignment.
* @param borderBottom The bottom border type.
* @param borderLeft The left border type.
* @param borderRight The right border type.
* @param borderTop The top border type.
* @param dataFormat The data format string.
* @param fontUnderline The font underline.
* @param fontStrikeout Whether the font is in strikeout.
* @param wrapText Whether text is wrapped.
* @param fillBackgroundColor The fill background color.
* @param fillForegroundColor The fill foreground color.
* @param fillPattern The fill pattern.
* @param verticalAlignment The vertical alignment.
* @param indention How many characters the text is indented.
* @param rotation How many degrees the text is rotated.
* @param bottomBorderColor The bottom border color.
* @param leftBorderColor The left border color.
* @param rightBorderColor The right border color.
* @param topBorderColor The top border color.
* @param fontCharset The font charset.
* @param fontTypeOffset The font type offset.
* @param locked Whether the cell is "locked".
* @param hidden Whether the cell is "hidden".
* @return A <code>CellStyle</code> that matches all given properties, or
* <code>null</code> if it doesn't exist.
*/
public CellStyle retrieveCellStyle(short fontBoldweight, boolean fontItalic, Color fontColor, String fontName,
short fontHeightInPoints, short alignment, short borderBottom, short borderLeft, short borderRight,
short borderTop, String dataFormat, byte fontUnderline, boolean fontStrikeout, boolean wrapText,
Color fillBackgroundColor, Color fillForegroundColor, short fillPattern, short verticalAlignment,
short indention, short rotation, Color bottomBorderColor, Color leftBorderColor, Color rightBorderColor,
Color topBorderColor, int fontCharset, short fontTypeOffset, boolean locked, boolean hidden)
{
String representation = getRepresentation(fontBoldweight, fontItalic, fontColor, fontName, fontHeightInPoints,
alignment, borderBottom, borderLeft, borderRight, borderTop, dataFormat, fontUnderline, fontStrikeout,
wrapText, fillBackgroundColor, fillForegroundColor, fillPattern, verticalAlignment, indention, rotation,
bottomBorderColor, leftBorderColor, rightBorderColor, topBorderColor, fontCharset, fontTypeOffset, locked,
hidden
);
CellStyle cs = myCellStyleMap.get(representation);
if (DEBUG)
{
if (cs != null)
System.err.println("CSCache hit : " + representation);
else
System.err.println("CSCache miss!: " + representation);
}
return cs;
}
示例15: getRepresentation
import org.apache.poi.ss.usermodel.Color; //导入依赖的package包/类
/**
* Gets the string representation of the given <code>CellStyle</code>.
* @param cs A <code>CellStyle</code>.
* @return The string representation.
*/
private String getRepresentation(CellStyle cs)
{
Font f = myWorkbook.getFontAt(cs.getFontIndex());
// Colors that need an instanceof check
Color fontColor;
Color bottomColor = null;
Color leftColor = null;
Color rightColor = null;
Color topColor = null;
if (cs instanceof HSSFCellStyle)
{
HSSFFont hf = (HSSFFont) f;
fontColor = hf.getHSSFColor((HSSFWorkbook) myWorkbook);
// HSSF only stores border colors if the borders aren't "NONE".
if (cs.getBorderBottom() != CellStyle.BORDER_NONE)
bottomColor = ExcelColor.getHssfColorByIndex(cs.getBottomBorderColor());
if (cs.getBorderLeft() != CellStyle.BORDER_NONE)
leftColor = ExcelColor.getHssfColorByIndex(cs.getLeftBorderColor());
if (cs.getBorderRight() != CellStyle.BORDER_NONE)
rightColor = ExcelColor.getHssfColorByIndex(cs.getRightBorderColor());
if (cs.getBorderTop() != CellStyle.BORDER_NONE)
topColor = ExcelColor.getHssfColorByIndex(cs.getTopBorderColor());
}
else if (cs instanceof XSSFCellStyle)
{
XSSFFont xf = (XSSFFont) f;
fontColor = xf.getXSSFColor();
XSSFCellStyle xcs = (XSSFCellStyle) cs;
bottomColor = xcs.getBottomBorderXSSFColor();
leftColor = xcs.getLeftBorderXSSFColor();
rightColor = xcs.getRightBorderXSSFColor();
topColor = xcs.getTopBorderXSSFColor();
}
else
throw new IllegalArgumentException("Bad CellStyle type: " + cs.getClass().getName());
return getRepresentation(f.getBoldweight(), f.getItalic(), fontColor, f.getFontName(),
f.getFontHeightInPoints(), cs.getAlignment(), cs.getBorderBottom(), cs.getBorderLeft(), cs.getBorderRight(),
cs.getBorderTop(), cs.getDataFormatString(), f.getUnderline(), f.getStrikeout(), cs.getWrapText(),
cs.getFillBackgroundColorColor(), cs.getFillBackgroundColorColor(), cs.getFillPattern(), cs.getVerticalAlignment(),
cs.getIndention(), cs.getRotation(), bottomColor, leftColor, rightColor,
topColor, f.getCharSet(), f.getTypeOffset(), cs.getLocked(), cs.getHidden());
}