Search in sources :

Example 1 with HSSFColor

use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.

the class HSSFHtmlHelper method styleColor.

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);
    }
}
Also used : HSSFColor(org.apache.poi.hssf.util.HSSFColor)

Example 2 with HSSFColor

use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.

the class HSSFExtendedColor method getIndexedRGB.

protected byte[] getIndexedRGB() {
    if (isIndexed() && getIndex() > 0) {
        int indexNum = getIndex();
        HSSFColor indexed = HSSFColor.getIndexHash().get(indexNum);
        if (indexed != null) {
            byte[] rgb = new byte[3];
            rgb[0] = (byte) indexed.getTriplet()[0];
            rgb[1] = (byte) indexed.getTriplet()[1];
            rgb[2] = (byte) indexed.getTriplet()[2];
            return rgb;
        }
    }
    // else
    return null;
}
Also used : HSSFColor(org.apache.poi.hssf.util.HSSFColor)

Example 3 with HSSFColor

use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.

the class TestUnfixedBugs method testBug57074.

@Test
public void testBug57074() throws IOException {
    Workbook wb = HSSFTestDataSamples.openSampleWorkbook("57074.xls");
    Sheet sheet = wb.getSheet("Sheet1");
    Row row = sheet.getRow(0);
    Cell cell = row.getCell(0);
    HSSFColor bgColor = (HSSFColor) cell.getCellStyle().getFillBackgroundColorColor();
    String bgColorStr = bgColor.getTriplet()[0] + ", " + bgColor.getTriplet()[1] + ", " + bgColor.getTriplet()[2];
    //System.out.println(bgColorStr);
    assertEquals("215, 228, 188", bgColorStr);
    HSSFColor fontColor = (HSSFColor) cell.getCellStyle().getFillForegroundColorColor();
    String fontColorStr = fontColor.getTriplet()[0] + ", " + fontColor.getTriplet()[1] + ", " + fontColor.getTriplet()[2];
    //System.out.println(fontColorStr);
    assertEquals("0, 128, 128", fontColorStr);
    wb.close();
}
Also used : HSSFColor(org.apache.poi.hssf.util.HSSFColor) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 4 with HSSFColor

use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.

the class ExcelToFoConverter method processCellStyle.

protected void processCellStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle, Element cellTarget, Element blockTarget) {
    blockTarget.setAttribute("white-space-collapse", "false");
    {
        String textAlign = ExcelToFoUtils.getAlign(cellStyle.getAlignment());
        if (ExcelToFoUtils.isNotEmpty(textAlign))
            blockTarget.setAttribute("text-align", textAlign);
    }
    if (cellStyle.getFillPattern() == 0) {
    // no fill
    } else if (cellStyle.getFillPattern() == 1) {
        final HSSFColor foregroundColor = cellStyle.getFillForegroundColorColor();
        if (foregroundColor != null)
            cellTarget.setAttribute("background-color", ExcelToFoUtils.getColor(foregroundColor));
    } else {
        final HSSFColor backgroundColor = cellStyle.getFillBackgroundColorColor();
        if (backgroundColor != null)
            cellTarget.setAttribute("background-color", ExcelToHtmlUtils.getColor(backgroundColor));
    }
    processCellStyleBorder(workbook, cellTarget, "top", cellStyle.getBorderTopEnum(), cellStyle.getTopBorderColor());
    processCellStyleBorder(workbook, cellTarget, "right", cellStyle.getBorderRightEnum(), cellStyle.getRightBorderColor());
    processCellStyleBorder(workbook, cellTarget, "bottom", cellStyle.getBorderBottomEnum(), cellStyle.getBottomBorderColor());
    processCellStyleBorder(workbook, cellTarget, "left", cellStyle.getBorderLeftEnum(), cellStyle.getLeftBorderColor());
    HSSFFont font = cellStyle.getFont(workbook);
    processCellStyleFont(workbook, blockTarget, font);
}
Also used : HSSFColor(org.apache.poi.hssf.util.HSSFColor) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 5 with HSSFColor

use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.

the class TestPaletteRecord method testDefaultPalette.

/**
     * Tests that the default palette matches the constants of HSSFColor
     */
@Test
public void testDefaultPalette() {
    PaletteRecord palette = new PaletteRecord();
    //make sure all the HSSFColor constants match
    Map<Integer, HSSFColor> colors = HSSFColor.getIndexHash();
    for (Entry<Integer, HSSFColor> entry : colors.entrySet()) {
        int index = entry.getKey();
        HSSFColor c = entry.getValue();
        short[] rgbTriplet = c.getTriplet();
        byte[] paletteTriplet = palette.getColor((short) index);
        String msg = "Expected HSSFColor constant to match PaletteRecord at index" + (index == c.getIndex2() ? "2" : "") + " 0x" + Integer.toHexString(index);
        assertEquals(msg, rgbTriplet[0], paletteTriplet[0] & 0xff);
        assertEquals(msg, rgbTriplet[1], paletteTriplet[1] & 0xff);
        assertEquals(msg, rgbTriplet[2], paletteTriplet[2] & 0xff);
    }
}
Also used : HSSFColor(org.apache.poi.hssf.util.HSSFColor) Test(org.junit.Test)

Aggregations

HSSFColor (org.apache.poi.hssf.util.HSSFColor)18 Test (org.junit.Test)4 Color (java.awt.Color)2 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)2 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)2 Cell (org.apache.poi.ss.usermodel.Cell)2 Row (org.apache.poi.ss.usermodel.Row)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 ExcelColDVO (com.kyj.fx.voeditor.visual.excels.base.ExcelColDVO)1 ExcelDataDVO (com.kyj.fx.voeditor.visual.excels.base.ExcelDataDVO)1 ExcelSVO (com.kyj.fx.voeditor.visual.excels.base.ExcelSVO)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Triplet (org.apache.poi.hwpf.converter.FontReplacer.Triplet)1 CellDateFormatter (org.apache.poi.ss.format.CellDateFormatter)1 CellStyle (org.apache.poi.ss.usermodel.CellStyle)1 Color (org.apache.poi.ss.usermodel.Color)1 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1