本文整理汇总了Java中org.apache.poi.hssf.util.HSSFColor.getTriplet方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFColor.getTriplet方法的具体用法?Java HSSFColor.getTriplet怎么用?Java HSSFColor.getTriplet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.util.HSSFColor
的用法示例。
在下文中一共展示了HSSFColor.getTriplet方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createColor
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的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;
}
示例2: convertToStardColor
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的package包/类
/**
* 单元格背景色转换
*/
private String convertToStardColor(HSSFColor hc) {
StringBuffer sb = new StringBuffer("");
if (hc != null) {
int a = HSSFColor.AUTOMATIC.index;
int b = hc.getIndex();
if (a == b) {
return null;
}
sb.append("#");
for (int i = 0; i < hc.getTriplet().length; i++) {
String str;
String strTmp = Integer.toHexString(hc.getTriplet()[i]);
if (strTmp != null && strTmp.length() < 2) {
str = "0" + strTmp;
} else {
str = strTmp;
}
sb.append(str);
}
}
return sb.toString();
}
示例3: testColorConversionHssf
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的package包/类
/**
* Test converting color from Meja to POI color and back again does not
* change the color value.
*
* This test checks the implementation for HSSF.
*/
@Test
public void testColorConversionHssf() {
PoiWorkbook.PoiHssfWorkbook wb = (PoiWorkbook.PoiHssfWorkbook) PoiWorkbookFactory.instance().createXls();
// HSSF maps colors to more or less matching nearest colors.
Set<String> used = new HashSet<>();
for (Color col : Color.values()) {
HSSFColor poiColor = wb.getPoiColor(col);
short[] t = poiColor.getTriplet();
Color expected = new Color(t[0], t[1], t[2]);
Color actual = wb.getColor(poiColor, Color.BLACK);
assertEquals(expected, actual);
used.add(expected.toString());
}
assertTrue(used.size()>20);
}
示例4: styleColor
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的package包/类
private void styleColor(Formatter out, String attr, short index) {
HSSFColor color = colors.getColor(index);
if (index == HSSF_AUTO.getIndex() || color == null) {
out.format(" /* %s: index = %d */%n", attr, index);
} else {
short[] rgb = color.getTriplet();
out.format(" %s: #%02x%02x%02x; /* index = %d */%n", attr, rgb[0], rgb[1], rgb[2],
index);
}
}
示例5: getRGB
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的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];
}
示例6: getHSSFColorHexString
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的package包/类
/**
* Get the hex string for a <code>HSSFColor</code>. Moved from test code.
* @param hssfColor A <code>HSSFColor</code>.
* @return The hex string.
* @since 0.5.0
*/
private static String getHSSFColorHexString(HSSFColor hssfColor)
{
short[] shorts = hssfColor.getTriplet();
StringBuilder hexString = new StringBuilder();
for (short s : shorts)
{
String twoHex = Integer.toHexString(0x000000FF & s);
if (twoHex.length() == 1)
hexString.append('0');
hexString.append(twoHex);
}
return hexString.toString();
}
示例7: getColor
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的package包/类
public static String getColor( HSSFColor color )
{
StringBuilder stringBuilder = new StringBuilder( 7 );
stringBuilder.append( '#' );
for ( short s : color.getTriplet() )
{
if ( s < 10 )
stringBuilder.append( '0' );
stringBuilder.append( Integer.toHexString( s ) );
}
String result = stringBuilder.toString();
if ( result.equals( "#ffffff" ) )
return "white";
if ( result.equals( "#c0c0c0" ) )
return "silver";
if ( result.equals( "#808080" ) )
return "gray";
if ( result.equals( "#000000" ) )
return "black";
return result;
}
示例8: shortToColor
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的package包/类
/**
* Converts a POI color to an AWT color.
*/
public static Color shortToColor(short xlsColorIndex) {
if (xlsColorIndex > 0) {
HSSFColor xlsColor = HSSFColor.getIndexHash().get(new Integer(xlsColorIndex));
if (xlsColor != null) {
short[] rgb = xlsColor.getTriplet();
return new Color(rgb[0], rgb[1], rgb[2]);
//return Color.decode(xlsColor.getHexString());
}
}
return null;
}
示例9: getColor
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的package包/类
private static Color getColor(org.apache.poi.ss.usermodel.Color c) {
if (c == null) {
return null;
} else if (c instanceof HSSFColor) {
HSSFColor hc = (HSSFColor)c;
short[] rgb = hc.getTriplet();
return new Color(rgb[0], rgb[1], rgb[2]);
} else if (c instanceof XSSFColor) {
XSSFColor xc = (XSSFColor)c;
byte[] data = null;
if (xc.getTint() != 0.0) {
data = getRgbWithTint(xc);
byte[] argb = xc.getARgb();
} else {
data = xc.getARgb();
}
if (data == null) {
return null;
}
int idx = 0;
int alpha = 255;
if (data.length == 4) {
alpha = data[idx++] & 0xFF;
}
int r = data[idx++] & 0xFF;
int g = data[idx++] & 0xFF;
int b = data[idx++] & 0xFF;
return new Color(r, g, b, alpha);
} else {
throw new IllegalStateException();
}
}
示例10: toHexColor
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的package包/类
public static String toHexColor(HSSFColor hssfColor) {
short[] rgb = hssfColor.getTriplet();
return String.format("#%02X%02X%02X", rgb[0], rgb[1], rgb[2]);
}
示例11: toRgbByte
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的package包/类
public static byte[] toRgbByte(HSSFColor hssfColor) {
short[] rgb = hssfColor.getTriplet();
return new byte[] { (byte)rgb[0], (byte)rgb[1], (byte)rgb[2] };
}
示例12: getNearestColor
import org.apache.poi.hssf.util.HSSFColor; //导入方法依赖的package包/类
/**
* Find a suitable color for the cell.
* <p/>
* The algorithm searches all available triplets, weighted by tripletvalue and
* tripletdifference to the other triplets. The color wins, which has the
* smallest triplet difference and where all triplets are nearest to the
* requested color.
*
* @param awtColor the awt color that should be transformed into an Excel color.
* @return the excel color index that is nearest to the supplied color.
*/
public static synchronized short getNearestColor(
final Color awtColor) {
if (triplets == null) {
triplets = HSSFColor.getTripletHash();
}
if (triplets == null || triplets.isEmpty()) {
System.out.println("Unable to get triplet hashtable");
return HSSFColor.BLACK.index;
}
short color = HSSFColor.BLACK.index;
double minDiff = Double.MAX_VALUE;
// get the color without the alpha chanel
final float[] hsb = Color.RGBtoHSB(awtColor.getRed(), awtColor
.getGreen(), awtColor.getBlue(), null);
float[] excelHsb = null;
final Iterator elements = triplets.values().iterator();
while (elements.hasNext()) {
final HSSFColor crtColor = (HSSFColor) elements.next();
final short[] rgb = crtColor.getTriplet();
excelHsb = Color.RGBtoHSB(rgb[0], rgb[1], rgb[2], excelHsb);
final double weight = 3.0d * Math.abs(excelHsb[0] - hsb[0])
+ Math.abs(excelHsb[1] - hsb[1])
+ Math.abs(excelHsb[2] - hsb[2]);
if (weight < minDiff) {
minDiff = weight;
if (minDiff == 0) {
// we found the color ...
return crtColor.getIndex();
}
color = crtColor.getIndex();
}
}
return color;
}