So, where do we store the pool? Can POI support add it into the spreadsheet?

Khanh

 

---------------------------------------------

You can easilly add this feature Rob.

 

Think about simple 'pooling' of which there are many examples in the core
API; all you need to do is create

some way of keeping track of the cell styles as you create them. As a crude
example, you could use an

ArrayList to hold references to all of your cell styles. As you come across
a requirement for a new cell

style simply query the ArrayList to see if one with those attributes already
exists and if it does grab the

exiting reference to it. If a suitable cell style does not exist, add the
new one to the list...etc. Or, you

could simply have a method called something like removeDuplicateStyles()
that you call prior to saving

the workbook away. This method would iterate thropugh the sheet removing any
duplicate cell styles. I am

not too sure about this and you would have to test it but I 

 do believ that the equals() method the the HSSFCellStyle class has been
over-ridden to make it easy to

compare cell styles for equality. I do have to agree with you

 however that this would incur some overhead but I do not feel that there is
anyway to avoid it.

 

By the way, the limit on cell styles IS imposed by Excel and POI merely has
to work within the constraint. HSSF

is a community project and I am pretty sure that if you want to contribute a
feature or features that could

improve this aspect of the API, then the development team would respond
positivly if you were to approach

them with an idea.

 

--- On Wed, 10/15/08, Rob Y <ryampolsky <at> yahoo.com> wrote:

From: Rob Y <ryampolsky <at> yahoo.com>

Subject: HSSFCellStyle - global styles vs individual cell styles

To: user <at> poi.apache.org

Date: Wednesday, October 15, 2008, 11:34 AM

 

In Apache POI-HSSF, it seems like the HSSFCellStyle is global to the

workbook.

I assume that means that in order to, say, color cells as you add them,

creating

a new HSSFCellStyle for each would be hugely inefficient.

In fact I've seen lots of messages here saying that Excel will complain if

you

create too many cell styles.

 

But if my data source makes it difficult to know all possible cell styles

upfront (especially, since cell styles are combinations of font, color,
border,

etc), how can I know when I need to create a new one?

I suppose I could keep a table of all the style parameter combinations I've

encountered, but doesn't the library already do this?

And if I did create a sheet where all the green cells shared a single cell

style, would a user changing a single cell's color end up changing them

all?

Or would Excel be smart enough to detect that the cell now needs a new style

created?

 

I guess this boils down to a few questions:

 

Is there a way to query your workbook while building it to find out whether
a

cell style you want to use matches one that's already in the workbook and

to use

that instead?

If so, wouldn't it be nice to automate that and allow you to just set

individual

styles without incurring the inefficiency?

 

I can't imagine Excel has a limit on how many unique combinations of cell

attributes you can have.

If that's true, does xls have some other mechanism for coloring cells, etc

that

isn't supported by poi?

 

Rob 

 

Reply via email to