Bug 46015 - simpler usage for HSSFCellStyle?
Summary: simpler usage for HSSFCellStyle?
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.1-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-15 13:37 UTC by littlenoodles
Modified: 2008-10-16 09:50 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description littlenoodles 2008-10-15 13:37:05 UTC
Just a suggestion...

It seems like the HSSFStyle API is designed more around the internals of the xls file format than around what a programmer would want to do when building a spreadsheet.

For example, I've been trying to figure out how to manage the global list of HSSFCellStyles and reuse existing ones where possible.  It seems like the easiest way to do this would be to build a reference style with all the settings you want for a particular cell and then enumerate over all the existing styles in the workbook to see if there's a match.

If so, would it not make sense to add the following methods to the HSSFCell class to automate that procedure and hide it from the user:

HSSFCellStyle getNewStyle();

Produce a temporary HSSFCellStyle, where you could set all the parameters you want, without attaching it to the workbook.

void applyNewStyle(HSSFCellStyle style);

Scan all the styles in the workbook and if there's a match, apply the existing style to the cell.  If not, attach the new style to the workbook and apply it to the cell.

It certainly seems like that's what Excel does when you restyle a cell.  It certainly does not just apply the change to a global style that the cell shares with others, in applying the change to all the shared cells.

Does this sound reasonable?  I'd submit a patch if I understood the POI codebase better.
Comment 1 Nick Burch 2008-10-16 07:45:53 UTC
You can probably already do most of this, with a little bit of fiddling. HSSFCellStyle.cloneStyleFrom(style), HSSFWorkbook.getNumCellStyles() and HSSFWorkbook.getCellStyleAt(idx) should be most of what you need

If you do wrap this up in an easier to use structure for your use case, do please submit a patch
Comment 2 littlenoodles 2008-10-16 08:58:52 UTC
Yeah, the approach you outlined is essentially how I thought I'd do it for my app.  I had just noticed that I wasn't alone in this confusion and had thought that it would be nice if the project either provided this guidance in the documentation or, even better, wrapped this behavior into a standard interface that would make cell styles much easier to use for most applications.

This is my first Java project, so I don't feel qualified to submit a patch (yet).  I was hoping that bugzilla might be a semi-appropriate place to make suggestions.  If not, is there a better place to submit it?  And is my suggestion just wrong-headed in terms of the goals of the project?
Comment 3 Nick Burch 2008-10-16 09:50:08 UTC
(In reply to comment #2)
> I had just noticed that I wasn't alone in this confusion and had thought
> that it would be nice if the project either provided this guidance in the
> documentation or, even better, wrapped this behavior into a standard interface
> that would make cell styles much easier to use for most applications.

Being an open source, volunteer project, the available features and documentation track what people are willing and able to contribute

If you'd like to write the code for this, we'd be happy to accept it. If you just want to document the workaround, we'd again be happy to add that to the overall docs :)