× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Darrell,

I hate explaining cell styles, because I just can't think of a great way to explain them. The basic idea you have to grasp is this:

Cell styles are not a property of individual cells, or individual sheets. They're created at the workbook level, and then are APPLIED to individual cells.

I keep trying to think of a good analogy that will make that crystal clear, but I just can't seem to come up with one. The best thing I've come up with is this:

You have a closet full of outfits. Each day you choose one outfit and dress up in that outfit. So a cell style is like a set of clothes stored in a closed... you can "dress up" each cell style by putting on the right set of clothes.

But, that's not a great analogy... 100 people can't be wearing the same set of clothes from the same closet, but 100 cells can all use the same cell style.

Err.. I guess you could think of a cell style as a (very fancy) edit code. It tells the system how to take the raw data of a cell and format it nicely for display.

Now, you can re-use the same cell style for different cells, just as you can re-use the same edit code. For example, if I use edit code L to format a number, I can still re-use edit code L on other numbers in different fields.. I can do that as much as I want... the same is true for a cell style. I create it once, it becomes a property of the workbook, and I can then apply that same "appearance" to as many cells as I like.

Hope that's clear.

A cell style is stored at the workbook level, and there's a limit to the number of cell styles that can be stored in a workbook (though, I don't remember what it is.) It would not make sense -- for example -- to create a new cell style for every single cell, because you'd quickly run out of styles.


All of the cell styles I need are used in sheets I previously created in the workbook, so your suggesting I should get the cell style from the workbook as in HSSFCell_getCellStyle...
Never used it before, does this mean I'll need to open an existing sheet?

Again, cell styles are not created at the sheet level. They're at the workbook level... so opening a sheet doesn't make sense.

HSSFCell_getCellStyle() takes a given cell as a parameter, and tells you which cell style object was used to format that cell. So if you have an existing cell that you know uses the appropriate cell style, you can use this API to retrieve that cell style.

The HSSFWorkbook class also has a method named getCellStyleAt() that lets you read the cell style table directly from the workbook. Unfortunately, cell styles don't have names associated with them, so you'd have to know (by number) where the style is stored in the workbook's array of styles (this might be problematic?)

For me, when I'm modifying an existing workbook, I typically am adding additional "rows" to an existing sheet, so I use HSSFCell_getCellStyle to retrieve the appropriate styles from the previous row and use them to apply the same styles to the new row I've added.


mmmmmmmmm The more I think about it the more I don't know


Me too!

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.