org.apache.poi.hssf.util.HSSFColor类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(163)

本文整理了Java中org.apache.poi.hssf.util.HSSFColor类的一些代码示例,展示了HSSFColor类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HSSFColor类的具体详情如下:
包路径:org.apache.poi.hssf.util.HSSFColor
类名称:HSSFColor

HSSFColor介绍

[英]Intends to provide support for the very evil index to triplet issue and will likely replace the color constants interface for HSSF 2.0. This class contains static inner class members for representing colors. Each color has an index (for the standard palette in Excel (tm) ), native (RGB) triplet and string triplet. The string triplet is as the color would be represented by Gnumeric. Having (string) this here is a bit of a collusion of function between HSSF and the HSSFSerializer but I think its a reasonable one in this case.
[中]打算为非常邪恶的索引到三元组问题提供支持,并可能取代HSSF 2.0的颜色常数接口。此类包含用于表示颜色的静态内部类成员。每种颜色都有一个索引(用于Excel(tm)中的标准调色板)、本机(RGB)三元组和字符串三元组。字符串三元组与Gnumeric表示的颜色相同。这里有(字符串)这是HSSF和HSSF序列化程序之间的功能共谋,但我认为在这种情况下这是合理的。

代码示例

代码示例来源:origin: org.apache.poi/poi

  1. /**
  2. * @see HSSFColor#getIndex()
  3. */
  4. public short getIndex() {
  5. return color.getIndex();
  6. }

代码示例来源:origin: org.apache.poi/poi

  1. /**
  2. * @see HSSFColor#getTriplet()
  3. */
  4. public short [] getTriplet() {
  5. return color.getTriplet();
  6. }

代码示例来源:origin: org.apache.poi/poi

  1. /**
  2. * @see HSSFColor#getHexString()
  3. */
  4. public String getHexString() {
  5. return color.getHexString();
  6. }

代码示例来源:origin: org.apache.poi/poi-ooxml

  1. /**
  2. * @param index
  3. * @return RGB bytes from HSSF default color by index
  4. */
  5. public static byte[] getDefaultRGB(int index) {
  6. HSSFColor hssfColor = HSSFColor.getIndexHash().get(index);
  7. if (hssfColor == null) return null;
  8. short[] rgbShort = hssfColor.getTriplet();
  9. return new byte[] {(byte) rgbShort[0], (byte) rgbShort[1], (byte) rgbShort[2]};
  10. }

代码示例来源:origin: org.apache.poi/poi

  1. public void setFontColor(Color color) {
  2. HSSFColor hcolor = HSSFColor.toHSSFColor(color);
  3. if (hcolor == null) {
  4. fontFormatting.setFontColorIndex((short)0);
  5. } else {
  6. fontFormatting.setFontColorIndex(hcolor.getIndex());
  7. }
  8. }

代码示例来源:origin: cn.afterturn/easypoi-base

  1. private void styleColor(Formatter out, String attr, short index) {
  2. HSSFColor color = colors.getColor(index);
  3. if (index == hssfAuto.getIndex() || color == null) {
  4. out.format(" /* %s: index = %d */%n", attr, index);
  5. } else {
  6. short[] rgb = color.getTriplet();
  7. out.format(" %s: #%02x%02x%02x; /* index = %d */%n", attr, rgb[0], rgb[1], rgb[2],
  8. index);
  9. }
  10. }

代码示例来源:origin: pentaho/pentaho-reporting

  1. public short getNearestColor( final Color awtColor ) {
  2. if ( lastUsedColor > 64 ) {
  3. // we ran out of palette... try to get nearest color then
  4. return StaticExcelColorSupport.getNearestColor( awtColor, usedTripplets );
  5. }
  6. final HSSFPalette palette = workbook.getCustomPalette();
  7. final HSSFColor hssfColor =
  8. palette.findColor( (byte) awtColor.getRed(), (byte) awtColor.getGreen(), (byte) awtColor.getBlue() );
  9. if ( hssfColor != null && hssfColor.getIndex() < lastUsedColor ) {
  10. return hssfColor.getIndex();
  11. } else {
  12. palette.setColorAtIndex( lastUsedColor, (byte) awtColor.getRed(), (byte) awtColor.getGreen(), (byte) awtColor
  13. .getBlue() );
  14. final HSSFColor color = palette.getColor( lastUsedColor );
  15. usedTripplets.put( color.getHexString(), color );
  16. return lastUsedColor++;
  17. }
  18. }

代码示例来源:origin: jasperreports/jasperreports

  1. Map triplets = HSSFColor.getTripletHash();
  2. if (triplets != null)
  3. rgb = crtColor.getTriplet();

代码示例来源:origin: com.haulmont.thirdparty/poi

  1. private static Hashtable<String,HSSFColor> createColorsByHexStringMap() {
  2. HSSFColor[] colors = getAllColors();
  3. Hashtable<String,HSSFColor> result = new Hashtable<String,HSSFColor>(colors.length * 3 / 2);
  4. for (int i = 0; i < colors.length; i++) {
  5. HSSFColor color = colors[i];
  6. String hexString = color.getHexString();
  7. if (result.containsKey(hexString)) {
  8. HSSFColor other = (HSSFColor)result.get(hexString);
  9. throw new RuntimeException(
  10. "Dup color hexString (" + hexString
  11. + ") for color (" + color.getClass().getName() + ") - "
  12. + " already taken by (" + other.getClass().getName() + ")"
  13. );
  14. }
  15. result.put(hexString, color);
  16. }
  17. return result;
  18. }

代码示例来源:origin: org.apache.poi/poi

  1. /**
  2. * This function returns all the Colours, stored in a Map that
  3. * can be edited. No caching is performed. If you don't need to edit
  4. * the table, then call {@link #getIndexHash()} which returns a
  5. * statically cached immutable map of colours.
  6. */
  7. public static Map<Integer,HSSFColor> getMutableIndexHash() {
  8. return createColorsByIndexMap();
  9. }

代码示例来源:origin: org.apache.poi/poi

  1. /**
  2. * this function returns all colors in a hastable. It's not implemented as a
  3. * static member/statically initialized because that would be dirty in a
  4. * server environment as it is intended. This means you'll eat the time
  5. * it takes to create it once per request but you will not hold onto it
  6. * if you have none of those requests.
  7. *
  8. * @return a Map containing all colors keyed by String gnumeric-like triplets
  9. */
  10. public static Map<String,HSSFColor> getTripletHash()
  11. {
  12. return createColorsByHexStringMap();
  13. }

代码示例来源:origin: caryyu/excel2pdf

  1. HSSFColor color = HSSFColor.getIndexHash().get(colorIndex);
  2. if (color != null) {
  3. int rbg = POIUtil.getRGB(color);

代码示例来源:origin: org.apache.poi/poi-examples

  1. private void styleColor(Formatter out, String attr, short index) {
  2. HSSFColor color = colors.getColor(index);
  3. if (index == HSSF_AUTO.getIndex() || color == null) {
  4. out.format(" /* %s: index = %d */%n", attr, index);
  5. } else {
  6. short[] rgb = color.getTriplet();
  7. out.format(" %s: #%02x%02x%02x; /* index = %d */%n", attr, rgb[0],
  8. rgb[1], rgb[2], index);
  9. }
  10. }
  11. }

代码示例来源:origin: org.apache.poi/poi

  1. @Override
  2. public void setTopBorderColor(Color color) {
  3. HSSFColor hcolor = HSSFColor.toHSSFColor(color);
  4. if (hcolor == null) {
  5. setTopBorderColor((short) 0);
  6. } else {
  7. setTopBorderColor(hcolor.getIndex());
  8. }
  9. }

代码示例来源:origin: org.apache.poi/poi

  1. protected byte[] getIndexedRGB() {
  2. if (isIndexed() && getIndex() > 0) {
  3. int indexNum = getIndex();
  4. HSSFColor indexed = HSSFColor.getIndexHash().get(indexNum);
  5. if (indexed != null) {
  6. byte[] rgb = new byte[3];
  7. rgb[0] = (byte) indexed.getTriplet()[0];
  8. rgb[1] = (byte) indexed.getTriplet()[1];
  9. rgb[2] = (byte) indexed.getTriplet()[2];
  10. return rgb;
  11. }
  12. } // else
  13. return null;
  14. }
  15. }

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

  1. private static Hashtable<String,HSSFColor> createColorsByHexStringMap() {
  2. HSSFColor[] colors = getAllColors();
  3. Hashtable<String,HSSFColor> result = new Hashtable<String,HSSFColor>(colors.length * 3 / 2);
  4. for (int i = 0; i < colors.length; i++) {
  5. HSSFColor color = colors[i];
  6. String hexString = color.getHexString();
  7. if (result.containsKey(hexString)) {
  8. HSSFColor other = (HSSFColor)result.get(hexString);
  9. throw new RuntimeException(
  10. "Dup color hexString (" + hexString
  11. + ") for color (" + color.getClass().getName() + ") - "
  12. + " already taken by (" + other.getClass().getName() + ")"
  13. );
  14. }
  15. result.put(hexString, color);
  16. }
  17. return result;
  18. }

代码示例来源:origin: org.apache.poi/poi

  1. /**
  2. * This function returns all the colours in an unmodifiable Map.
  3. * The map is cached on first use.
  4. *
  5. * @return a Map containing all colours keyed by <tt>Integer</tt> excel-style palette indexes
  6. */
  7. public static synchronized Map<Integer,HSSFColor> getIndexHash() {
  8. if(indexHash == null) {
  9. indexHash = Collections.unmodifiableMap( createColorsByIndexMap() );
  10. }
  11. return indexHash;
  12. }
  13. /**

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

  1. /**
  2. * this function returns all colors in a hastable. It's not implemented as a
  3. * static member/statically initialized because that would be dirty in a
  4. * server environment as it is intended. This means you'll eat the time
  5. * it takes to create it once per request but you will not hold onto it
  6. * if you have none of those requests.
  7. *
  8. * @return a Map containing all colors keyed by String gnumeric-like triplets
  9. */
  10. public static Map<String,HSSFColor> getTripletHash()
  11. {
  12. return createColorsByHexStringMap();
  13. }

代码示例来源:origin: org.jeecg/easypoi-base

  1. private void styleColor(Formatter out, String attr, short index) {
  2. HSSFColor color = colors.getColor(index);
  3. if (index == HSSF_AUTO.getIndex() || color == null) {
  4. out.format(" /* %s: index = %d */%n", attr, index);
  5. } else {
  6. short[] rgb = color.getTriplet();
  7. out.format(" %s: #%02x%02x%02x; /* index = %d */%n", attr, rgb[0], rgb[1], rgb[2],
  8. index);
  9. }
  10. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

  1. /**
  2. * @see HSSFColor#getTriplet()
  3. */
  4. public short [] getTriplet() {
  5. return color.getTriplet();
  6. }

相关文章