poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 51236] Font color set incorrectly for black and white color using RGB values
Date Mon, 13 Jun 2011 19:55:51 GMT

--- Comment #10 from jxz164@hotmail.com 2011-06-13 19:55:51 UTC ---
I am unable to create 4 part color for the Font using the POI library. For

XSSFColor CW = new XSSFColor(new byte[] { (byte) -1, (byte) 255, (byte) 255,
(byte) 255 });

and set the Font Color to CW.

The generated xlsx file contains

<color rgb="FFFFFF"/>

instead of

<color rgb="FFFFFFFF"/>

in the styles.xml file. The problem with this is that when you unload such
color representation, you will get rgb value 000000 (which is wrong)!

If you have a way to get the 4-part color for the Font color, please let me

However, such 4-color part seems to work for Foreground. Please see code

package org.apache.poi.ss.examples;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFFont;

import java.awt.Color;
import java.io.FileOutputStream;
import java.util.HashMap;

public class TestFontColor {

    private static HashMap createStyles(Workbook wb){

        HashMap m = new HashMap();
        XSSFColor CW = new XSSFColor(new byte[] { (byte) -1, (byte) 255, (byte)
255, (byte) 255 });
        XSSFColor CB = new XSSFColor(new byte[] { (byte) -1, (byte) 0, (byte)
0, (byte) 0 });

        XSSFCellStyle styleX = (XSSFCellStyle)wb.createCellStyle(); 
        XSSFFont fontX = (XSSFFont) wb.createFont();
        fontX.setColor(CW); //do it again
        fontX.setFontHeightInPoints((short) 29);
        styleX.setFillPattern((short) 1);
        m.put("WHITE", styleX);

        XSSFCellStyle styleY = (XSSFCellStyle) wb.createCellStyle();
        XSSFFont fontY = (XSSFFont) wb.createFont();
        fontY.setColor(CB); //FFFFFF returns black
        fontY.setFontHeightInPoints((short) 23);
        m.put("BLACK", styleY);

        return m;


    public static void main(String[] args) throws Exception {
        Workbook wb = new XSSFWorkbook();  //or new HSSFWorkbook();
        Sheet sheet = wb.createSheet("Fonts");

        HashMap map = createStyles(wb);

        Cell cell0 = sheet.createRow(0).createCell(0);
        cell0.setCellStyle((CellStyle) map.get("WHITE"));

        Cell cell1 = sheet.createRow(1).createCell(0);
        cell1.setCellStyle((CellStyle) map.get("BLACK"));

        // Write the output to a file
        FileOutputStream fileOut = new

Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org

View raw message