Package org.apache.poi.hssf.usermodel

Examples of org.apache.poi.hssf.usermodel.HSSFPalette$CustomColor


    this.usedTripplets = new HashMap();
  }

  public HSSFColor getColor(final short index)
  {
    final HSSFPalette palette = workbook.getCustomPalette();
    return palette.getColor(index);
  }
View Full Code Here


    {
      // we ran out of palette... try to get nearest color then
      return StaticExcelColorSupport.getNearestColor(awtColor, usedTripplets);
    }

    final HSSFPalette palette = workbook.getCustomPalette();
    final HSSFColor hssfColor = palette.findColor((byte) awtColor.getRed(),
        (byte) awtColor.getGreen(),
        (byte) awtColor.getBlue());

    if (hssfColor != null && hssfColor.getIndex() < lastUsedColor)
    {
      return hssfColor.getIndex();
    }
    else
    {
      palette.setColorAtIndex(lastUsedColor, (byte) awtColor.getRed(),
          (byte) awtColor.getGreen(),
          (byte) awtColor.getBlue());
      final HSSFColor color = palette.getColor(lastUsedColor);
      usedTripplets.put(color.getHexString(), color);
      return lastUsedColor++;
    }
  }
View Full Code Here

    this.usedTripplets = new HashMap<String,HSSFColor>();
  }

  public HSSFColor getColor(final short index)
  {
    final HSSFPalette palette = workbook.getCustomPalette();
    return palette.getColor(index);
  }
View Full Code Here

    {
      // we ran out of palette... try to get nearest color then
      return StaticExcelColorSupport.getNearestColor(awtColor, usedTripplets);
    }

    final HSSFPalette palette = workbook.getCustomPalette();
    final HSSFColor hssfColor = palette.findColor((byte) awtColor.getRed(),
        (byte) awtColor.getGreen(),
        (byte) awtColor.getBlue());

    if (hssfColor != null && hssfColor.getIndex() < lastUsedColor)
    {
      return hssfColor.getIndex();
    }
    else
    {
      palette.setColorAtIndex(lastUsedColor, (byte) awtColor.getRed(),
          (byte) awtColor.getGreen(),
          (byte) awtColor.getBlue());
      final HSSFColor color = palette.getColor(lastUsedColor);
      usedTripplets.put(color.getHexString(), color);
      return lastUsedColor++;
    }
  }
View Full Code Here

    }

    public short getColorIndex(Color color) {
        Workbook workbook = getWorkbook(true);
        if (workbook instanceof HSSFWorkbook) {
            HSSFPalette palette = ((HSSFWorkbook) workbook).getCustomPalette();
            byte r = toRgb(color.getRed());
            byte g = toRgb(color.getGreen());
            byte b = toRgb(color.getBlue());

            HSSFColor index = palette.findColor(r, g, b);
            if (index == null) {
                index = palette.findSimilarColor(r, g, b);
            }
            return index.getIndex();
        }
        throw new IllegalStateException("Unexpected workbook type: " + workbook.getClass());
    }
View Full Code Here

                    HSSFSheet hssfSheet = (HSSFSheet)sheet;
                    HSSFCell hssfCell = (HSSFCell)cell;
                    HSSFCellStyle style = hssfCell.getCellStyle();
//                    判断一下如果式样中有斜杠,那么写一个斜杠
                   
                    HSSFPalette palette = hssfSheet.getWorkbook().getCustomPalette();
                    styleApplier4XLS(td,style,hssfSheet.getWorkbook(),palette);
                  }else{
                    XSSFSheet xssfSheet = (XSSFSheet)sheet;
                    XSSFCell xssfCell = (XSSFCell)cell;
                    XSSFCellStyle style = xssfCell.getCellStyle();
View Full Code Here

            if(style!=null){
              cell.setCellStyle(style);
            }else{
                style = sheet.getWorkbook()
                    .createCellStyle();
                HSSFPalette palette = sheet.getWorkbook()
                    .getCustomPalette();
                HSSFFont font = sheet.getWorkbook().createFont();
                styleApplier(style, font, td, palette,styleContainer);
                cell.setCellStyle(style);
                styleContainer.cellStyleMap.put(styleKey, style);
View Full Code Here

  private HSSFColor getHSSFColor(final HSSFWorkbook workbook, final Color color) {
    byte red = (byte) color.getRed();
    byte green = (byte) color.getGreen();
    byte blue = (byte) color.getBlue();
    HSSFPalette palette = workbook.getCustomPalette();

    HSSFColor c = palette.findSimilarColor(red, green, blue);
    if (c == null) {
      try {
        c = palette.addColor(red, green, blue);
      } catch (RuntimeException e) {
        c = palette.findSimilarColor(red, green, blue);
      }
    }
    return c;
  }
View Full Code Here


    public void setUp()
    {
        _palette = new PaletteRecord();
        _hssfPalette = new HSSFPalette(_palette);
    }
View Full Code Here

    public void testCustomPalette() {
        //reading sample xls
        HSSFWorkbook book = HSSFTestDataSamples.openSampleWorkbook("Simple.xls");

        //creating custom palette
        HSSFPalette palette = book.getCustomPalette();
        palette.setColorAtIndex((short) 0x12, (byte) 101, (byte) 230, (byte) 100);
        palette.setColorAtIndex((short) 0x3b, (byte) 0, (byte) 255, (byte) 52);

        //writing to disk; reading in and verifying palette
        book = HSSFTestDataSamples.writeOutAndReadBack(book);

        palette = book.getCustomPalette();
        HSSFColor color = palette.getColor(HSSFColor.CORAL.index)//unmodified
        assertNotNull("Unexpected null in custom palette (unmodified index)", color);
        short[] expectedRGB = HSSFColor.CORAL.triplet;
        short[] actualRGB = color.getTriplet();
        String msg = "Expected palette position to remain unmodified";
        assertEquals(msg, expectedRGB[0], actualRGB[0]);
        assertEquals(msg, expectedRGB[1], actualRGB[1]);
        assertEquals(msg, expectedRGB[2], actualRGB[2]);

        color = palette.getColor((short) 0x12);
        assertNotNull("Unexpected null in custom palette (modified)", color);
        actualRGB = color.getTriplet();
        msg = "Expected palette modification to be preserved across save";
        assertEquals(msg, (short) 101, actualRGB[0]);
        assertEquals(msg, (short) 230, actualRGB[1]);
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.usermodel.HSSFPalette$CustomColor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.