If it is working go ahead. The code I quoted from is from a special class of ours that we use to manage Styles in our XLS creation process.

It helps to remind everyone that styles are stored in the workbook and then later associated with a cell. It really helps to manage your styles as quickly as possible, and that is what you seem to be doing since you are basing things the column header style.

Think of it as if the Excel workbook had CSS. Any attribute difference requires another class.

Is it going to be removed in a later release?

I doubt it. It should be deprecated first before it is removed.

Dave

On Jan 9, 2009, at 1:59 PM, Mark Hansen wrote:


Thank you for your help, David. Are you saying that I should not close the
style using
the cloneStyleFrom() method on the HSSFCellStyle object? This method is in
the
3.2-FINAL release I'm using and seems to be working.

Is it going to be removed in a later release?

Thanks,


David Fisher wrote:

You can clone using something like:

    public static HSSFCellStyle cloneStyle(HSSFWorkbook wb,
HSSFCellStyle src){
        HSSFCellStyle style = wb.createCellStyle();
        style.setFont(wb.getFontAt(src.getFontIndex()));
        style.setAlignment(src.getAlignment());
        style.setBorderBottom(src.getBorderBottom());
        style.setBorderLeft(src.getBorderLeft());
        style.setBorderRight(src.getBorderRight());
        style.setBorderTop(src.getBorderTop());
        style.setBottomBorderColor(src.getBottomBorderColor());
        style.setDataFormat(src.getDataFormat());
        style.setFillBackgroundColor(src.getFillBackgroundColor());
        style.setFillForegroundColor(src.getFillForegroundColor());
        style.setFillPattern(src.getFillPattern());
        style.setHidden(src.getHidden());
        style.setIndention(src.getIndention());
        style.setLeftBorderColor(src.getLeftBorderColor());
        style.setLocked(src.getLocked());
        style.setRightBorderColor(src.getRightBorderColor());
        style.setRotation(src.getRotation());
        style.setTopBorderColor(src.getTopBorderColor());
        style.setVerticalAlignment(src.getVerticalAlignment());
        style.setWrapText(src.getWrapText());
        return style;
    }

Save all your new and different formats in an Array or HashMap.

Add variations as you need them anything different in the style is
another HSSFCellStyle object attached to the HSSFWorkbook. Use  Clone
to add new variations.

To set the style of a cell just call
HSSFCell.setCellStyle(HSSFCellStyle style).

You can use HSSFWorkbook.getNumCellStyles() and
HSSFWorkbook.getCellStyleAt(short idx) to retrieve the styles that are
already in the file.

Good luck.

Regards,
Dave




--
View this message in context: 
http://www.nabble.com/Applying-a-data-format-to-a-style-for-one-cell-affects-other-cells--tp21362472p21379470.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@poi.apache.org
For additional commands, e-mail: user-h...@poi.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@poi.apache.org
For additional commands, e-mail: user-h...@poi.apache.org

Reply via email to