Hello Mark, Can we have a look at some code please? We need to know how you are getting the cell styles from the template in the firast place, how you are storing them, what you are doing when you create a cell, etc.
In your case, I would create a pool of cell styles - use one of the collections classes such as the HashMap that allows you to associate column numbers with cell styles. Typically, you would populate this collection once only, at the start of the sheet creation process. It is then possible to write some code that says, in effect, what is the column number, get me that cell style and apply it. Secondly, where does the data come from? You really do need, if it is possible, to place data of the correct type into a cell by setting the cells type and calling the correct method to set it's value. Assuming that you are reading a series of Strings from something like a CSV file, have you considered using Regular Expressions to test the data type, convert it appropriately and then place it into a cell of the appropriate data type? Somewhere, I have some code that does this - that is to read a CSV file, test each item against a regular expression to determine type and then populate a worksheet. If you want, I can post it for you later today, just let me know. --- On Thu, 1/8/09, Mark Hansen <[email protected]> wrote: From: Mark Hansen <[email protected]> Subject: RE: Applying a data format to a style for one cell affects other cells? To: [email protected] Date: Thursday, January 8, 2009, 8:39 PM Winarto-2 wrote: > > Hi Mark, > > As far as I understand, style is available in workbook level, and hence > when you're doing "HSSFStyle localStyle = cell.getCellStyle()" you're > actually getting the style reference from the workbook that is applied > to the particular cell. So If you get the cell style and modify it, > you're actually modifying the style of all cells in the workbook that is > using that style. > > Cheers, > Winarto > > Hello and thank you for your response. Can you please tell me then how I am supposed to create styles for each of the cells in the sheet? If I create a new style for each cell I lose the formatting applied to the cell in the template and I get an error that I've created too many styles. All I really want to do is change the data formatting on a per-cell basis (actually, the formatting will be the same for that cell in every row). Is there a way I can apply formatting to a cell without having it affect all cells - without creating a new cell style for each cell? Thanks, -- View this message in context: http://www.nabble.com/Applying-a-data-format-to-a-style-for-one-cell-affects-other-cells--tp21362472p21366134.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
