export data from jtable to Excel 2007

A

Anabolik

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);
 
J

John B. Matthews

Anabolik said:
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 said:
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().

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

John B. Matthews

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


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

Anabolik

I fixed setFillPattern() and all works fine in Office 2007, but it is
not good in Office 2003. Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top