當前位置: 首頁>>代碼示例>>Java>>正文


Java HSSFColor.getTriplet方法代碼示例

本文整理匯總了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;
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:40,代碼來源:JavaToExcel.java

示例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();
}
 
開發者ID:MobClub,項目名稱:BBSSDK-for-Android,代碼行數:26,代碼來源:OfficeConverter.java

示例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);
}
 
開發者ID:xzel23,項目名稱:meja,代碼行數:22,代碼來源:PoiTest.java

示例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);
    }
}
 
開發者ID:rushingpig,項目名稱:poix,代碼行數:11,代碼來源:StylerHelper.java

示例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];
}
 
開發者ID:hishidama,項目名稱:embulk-parser-poi_excel,代碼行數:28,代碼來源:PoiExcelColorVisitor.java

示例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();
}
 
開發者ID:rmage,項目名稱:gnvc-ims,代碼行數:20,代碼來源:SheetUtil.java

示例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;
}
 
開發者ID:rmage,項目名稱:gnvc-ims,代碼行數:28,代碼來源:AbstractExcelUtils.java

示例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;
}
 
開發者ID:foxerfly,項目名稱:Joeffice,代碼行數:15,代碼來源:CellUtils.java

示例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();
	}
}
 
開發者ID:shunjikonishi,項目名稱:excel2canvas,代碼行數:33,代碼來源:ExcelColor.java

示例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]);
}
 
開發者ID:tecsinapse,項目名稱:tecsinapse-data-io,代碼行數:5,代碼來源:StyleColorUtil.java

示例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] };
}
 
開發者ID:tecsinapse,項目名稱:tecsinapse-data-io,代碼行數:5,代碼來源:WorkbookUtil.java

示例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;
}
 
開發者ID:nextreports,項目名稱:nextreports-engine,代碼行數:52,代碼來源:ExcelColorSupport.java


注:本文中的org.apache.poi.hssf.util.HSSFColor.getTriplet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。