poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MSB <markbrd...@tiscali.co.uk>
Subject Re: DO NOT REPLY [Bug 48962] New: XSSFColor.getRgb() always returns null
Date Tue, 23 Mar 2010 12:31:43 GMT

Earlier this morning, I had the chance to play with some code and now that I
am having a break at work, can post this message to you.

Though I am not one of the developers of the API and cannot offer any direct
help, I have been doing a little digging around and have found that the
problem may not lie with POI but with one of the dependencies; a library
that the project relies upon. In this case it is the ooxml-schemas-1.0.jar.

Looking through the source code for the XSSFColor class, I found that the
getRgb() method looks like this;

     * Standard Alpha Red Green Blue ctColor value (ARGB).
    public byte[] getRgb() {
		return ctColor.getRgb();

which, as you can see, simply returns the result of calling the getRgb()
method on a local instance variable called ctColor. This variable holds a
reference to an instance of the
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor class which is
defined within that archive I mentioned earlier.

Like you, I found that the call to the getRgb() method on my XSSFColor
object returned null so I decided to take matters a little further. The
first thing I did was to call the getCTColor() method on an instance of the
XSSFColor class so that I could call the CTColor classes getRgb() method
directly and this also resulted in the returne value of null. Once I had
that CTColor class instance in hand, I noticed other methods and one of
these piqued my intertest, isSetRgb() which is declared to return a boolean
value. As I do not have the source for the CTColor class at hand I cannot be
certain about what this method does but it does not seem unreasonable to
assume it will indicate whether the colour of the cell has been set using
the traditional RGB values. Interestingly, if I call that method, it returns
false so the question that springs to my mind is, does this mean that the
cells colour is not available as an RGB value? I had simply selected the
colour from the Excel colour picker and can not be sure how this would be
encoded within the xml that describes the worksheet. Just for reference,
here is the code I played with;

public static void main(String[] args) {
        File inputFile = null;
        File outputFile = null;
        FileInputStream fis = null;
        FileOutputStream fos = null;
        XSSFWorkbook workbook = null;
        XSSFSheet sheet = null;
        XSSFRow row = null;
        XSSFCell cell = null;
        XSSFCellStyle style = null;
        XSSFColor color = null;

        try {

            inputFile = new File("C:/temp/Colour Test.xlsx");
            fis = new FileInputStream(inputFile);
            workbook = new XSSFWorkbook(fis);

            sheet = workbook.getSheetAt(0);
            row = sheet.getRow(0);
            cell = row.getCell(0);
            style = cell.getCellStyle();
            color = style.getFillBackgroundXSSFColor();


                 ctColor = color.getCTColor();



        catch(IOException ioEx) {
            System.out.println("Caught an: " + ioEx.getClass().getName());
            System.out.println("Message: " + ioEx.getMessage());
            System.out.println("Stacktrace follows:.....");

I do not know if the developers of POI have access to the source for the
ooxml-schemas archive as I believe it is developed by another group of
programmers. It may be that the only way to definitively answer your
question is to forward it to those people.


Mark B

Bugzilla from bugzilla@apache.org wrote:
> https://issues.apache.org/bugzilla/show_bug.cgi?id=48962
>            Summary: XSSFColor.getRgb() always returns null
>            Product: POI
>            Version: 3.6
>           Platform: Macintosh
>         OS/Version: Mac OS X 10.4
>             Status: NEW
>           Severity: normal
>           Priority: P2
>          Component: XSSF
>         AssignedTo: dev@poi.apache.org
>         ReportedBy: mkbitbucket@mac.com
> Created an attachment (id=25167)
>  --> (https://issues.apache.org/bugzilla/attachment.cgi?id=25167)
> Example file with font and background colors
> When examining an XLSX file created with Microsoft Excel that has both
> font
> colors and background colors in it, those colors cannot be extracted
> because
> the XSSFColor method always returns null.
> 1) Open the attached XLSX file (or any XLSX file that has a font color or
> fill
> color)
> 2) Navigate the sheet to one of the cells with color
> 3) Get that cell's style and font and notice that the getXSSFColor()
> method
> returns non-null XSSFColor
> 4) Call getRgb() on the XSSFColor and receive null value in return
> An array with the RGB values should be returned.
> To make this bug more painful, I have been unable to find any workaround.
> -- 
> 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 this message in context: http://old.nabble.com/DO-NOT-REPLY--Bug-48962--New%3A-XSSFColor.getRgb%28%29-always-returns-null-tp27993612p28000157.html
Sent from the POI - Dev mailing list archive at Nabble.com.

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

View raw message