You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2011/02/15 17:23:32 UTC

DO NOT REPLY [Bug 50786] New: XSSFColor.getRgb() returns null for Excel 97-2003 indexed colors

https://issues.apache.org/bugzilla/show_bug.cgi?id=50786

           Summary: XSSFColor.getRgb() returns null for Excel 97-2003
                    indexed colors
           Product: POI
           Version: 3.7
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: andrei.astrouski@gmail.com


Steps:
1. Open old.xls Excel file (see in attachment).
2. Create new XLSX Excel file.
2. Copy cell with colored background from old.xls to new xlsx.
3. Process new xlsx doc with poi.
4. Get cell background color:
cell.getCellStyle().getFillForegroundXSSFColor().getRgb()

Actual: null
Expected: rgb byte array

-- 
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


DO NOT REPLY [Bug 50786] XSSFColor.getRgb() returns null for Excel 97-2003 indexed colors

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50786

--- Comment #3 from andrei <an...@gmail.com> 2011-02-16 05:56:04 EST ---
styles.xml
<fgColor indexed="42"/>
Color is stored as indexed.

Possible solution:

XSSFColor color = ..;
short colorIndex = color.getIndexed();
HSSFColor indexedColor = HSSFColor.getIndexHash().get(colorIndex);
byte[] rgb = indexedColor.getTriplet();

-- 
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


DO NOT REPLY [Bug 50786] XSSFColor.getRgb() returns null for Excel 97-2003 indexed colors

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50786

--- Comment #7 from andrei <an...@gmail.com> 2011-03-02 10:41:20 EST ---
Thanks, it's a good idea

-- 
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


DO NOT REPLY [Bug 50786] XSSFColor.getRgb() returns null for Excel 97-2003 indexed colors

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50786

--- Comment #5 from andrei <an...@gmail.com> 2011-03-02 09:31:08 EST ---
Noticed that indexed colors hashtable is not stored in HSSFColor. So
getRGBOrARGB() method calls HSSFColor.getIndexHash() whitch every time (fill
color, text color, border color) builds color hashtable. It's very slowly.

HSSFColor.getIndexHash() method has comment:
"this function returns all colors in a hastable.  Its not implemented as a
 static member/staticly initialized because that would be dirty in a
 server environment as it is intended.  This means you'll eat the time
 it takes to create it once per request but you will not hold onto it
 if you have none of those requests."

-- 
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


DO NOT REPLY [Bug 50786] XSSFColor.getRgb() returns null for Excel 97-2003 indexed colors

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50786

--- Comment #1 from andrei <an...@gmail.com> 2011-02-15 11:26:26 EST ---
Created an attachment (id=26661)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=26661)
Excel 97-2003 file

-- 
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


DO NOT REPLY [Bug 50786] XSSFColor.getRgb() returns null for Excel 97-2003 indexed colors

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50786

Nick Burch <ni...@alfresco.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #2 from Nick Burch <ni...@alfresco.com> 2011-02-15 11:51:48 EST ---
Can you unzip the file (.xlsx is a zip of xml files), and track down where your
colour actually gets stored?

-- 
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


DO NOT REPLY [Bug 50786] XSSFColor.getRgb() returns null for Excel 97-2003 indexed colors

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50786

Nick Burch <ni...@alfresco.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #4 from Nick Burch <ni...@alfresco.com> 2011-02-18 12:42:14 EST ---
Thanks for the investigating, sample file and proposed fix

I've added the HSSFColor lookup inside the getRGB method and added a unit test
for it in r1072082.

-- 
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


DO NOT REPLY [Bug 50786] XSSFColor.getRgb() returns null for Excel 97-2003 indexed colors

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50786

Nick Burch <ni...@alfresco.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #8 from Nick Burch <ni...@alfresco.com> 2011-03-04 07:54:54 EST ---
Change committed in r1077920.

Almost everyone seemed to just call getIndexedHash().get(..) so they will get
the speedup with no need to change anything

In the very rare case that you were relying on editing the old hashtable,
getModifiableIndexedHash will provide that.

-- 
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


DO NOT REPLY [Bug 50786] XSSFColor.getRgb() returns null for Excel 97-2003 indexed colors

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50786

--- Comment #9 from andrei <an...@gmail.com> 2011-03-04 08:22:49 EST ---
Excellent!

-- 
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


DO NOT REPLY [Bug 50786] XSSFColor.getRgb() returns null for Excel 97-2003 indexed colors

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50786

Nick Burch <ni...@alfresco.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |

--- Comment #6 from Nick Burch <ni...@alfresco.com> 2011-03-02 10:00:21 EST ---
(In reply to comment #5)
> HSSFColor.getIndexHash() method has comment:
> "this function returns all colors in a hastable.  Its not implemented as a
>  static member/staticly initialized because that would be dirty in a
>  server environment as it is intended.  This means you'll eat the time
>  it takes to create it once per request but you will not hold onto it
>  if you have none of those requests."

I think we should probably replace this with a lazy initialized static cache on
HSSFColor. That way your first call may be a little slow while it's built, but
all other calls on the server will then be fast.

My plan would be to have it return an immutable hash which is statically
cached, but also offer a 2nd method that will return a writable hash for anyone
currently doing anything odd

I could swap that round with the new method name for the static cache version,
and the old method name for the mutable one, if someone can think of a good
reason why to do it that way!

-- 
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