From: Anabolik on
I export the data from JTable to the Excel file and set some colors
for the cells. All works fine except the Excel 2007. The data is
exported, but colors are not. Can somebody help?

There is the code of setting the color:
style.setFillPattern(HSSFColor.LIGHT_YELLOW.index);
style.setFillBackgroundColor(HSSFColor.LIGHT_YELLOW.index);
style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
From: John B. Matthews on
In article
<e171f636-90a0-4d76-b83f-6c9e1a8e6f0d(a)l36g2000yqb.googlegroups.com>,
Anabolik <bumsys(a)gmail.com> wrote:

> I export the data from JTable to the Excel file and set some colors
> for the cells. All works fine except the Excel 2007. The data is
> exported, but colors are not. Can somebody help?

I assume you are using <http://poi.apache.org>.

> There is the code of setting the color:
> style.setFillPattern(HSSFColor.LIGHT_YELLOW.index);

HSSFColor.LIGHT_YELLOW.index is not a valid parameter to setFillPattern().

<http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/CellStyle.html#setFillPattern(short)>

> style.setFillBackgroundColor(HSSFColor.LIGHT_YELLOW.index);
> style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);

Assuming that style is of type CellStyle, you might verify that
setCellStyle() is being invoked on the target cell.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Anabolik on
I use the class HSSFCellStyle.
From: John B. Matthews on
In article
<e75596ec-c341-4c09-b626-54c672dc7892(a)u22g2000yqf.googlegroups.com>,
Anabolik <bumsys(a)gmail.com> wrote:
> Anabolik <bumsys(a)gmail.com> wrote:
>
> > I export the data from JTable to the Excel file and set some colors
> > for the cells. All works fine except the Excel 2007. The data is
> > exported, but colors are not. Can somebody help?
>
> I assume you are using <http://poi.apache.org>.
>
> > There is the code of setting the color:
> > style.setFillPattern(HSSFColor.LIGHT_YELLOW.index);
>
> HSSFColor.LIGHT_YELLOW.index is not a valid parameter to setFillPattern().
> <http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/CellStyle.html#setFillPattern(short)>
>
> > style.setFillBackgroundColor(HSSFColor.LIGHT_YELLOW.index);
> > style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
>
> Assuming that style is of type CellStyle, you might verify that
> setCellStyle() is being invoked on the target cell.

> I use the class HSSFCellStyle.

OK, HSSFCellStyle implements the interface CellStyle, but it's never too
soon to learn to code to the interface:

<http://www.javaworld.com/javaworld/jw-08-1999/jw-08-interfaces.html>

In this case, HSSFCellStyle is the desired implementing class, but that
may change. For example, your vendor may abandon the Horrible Spread
Sheet Format (HSSF) in favor of the XML Spread Sheet Format (XSSF),
which is realized in XSSFCellStyle. By using the interface type, future
maintenance will be correspondingly easier.

So, did fixing setFillPattern() and using setCellStyle() help?

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Anabolik on
I fixed setFillPattern() and all works fine in Office 2007, but it is
not good in Office 2003. Thank you.