Hello Rob If I remember correctly, getFormat() will take care of part of the problem for you - it will check to see if a format exists with those features and, if not, add it to the collection for the workbook.
As for the first part of your question, I cannot offer an answer. I would assume however that there is no way to separate the two pieces of information - that is to specify that the number have a decimal portion in the format and the number of places separately. Of course, you could do something similar in your own application by creating a format class that would contain all of the formatting information to be parsed just before you called the write() method. May even look at it myself someday. --- On Mon, 11/24/08, Rob Y <[EMAIL PROTECTED]> wrote: From: Rob Y <[EMAIL PROTECTED]> Subject: number of decimal places in data formats To: [email protected] Date: Monday, November 24, 2008, 3:06 PM I'm writing code to dynamically assign an appropriate data type and format to data presented as strings. That is, I check the string for dollar, percentage, numeric or date data before defaulting to string data. All works fine (though it's a pain to have to do all that - it'd be nice to have a method somewhere in POI to analyze a string and produce a data type, format and optional numeric value in some highly optimized way). Anyway, my problem comes with decimals. I'm able to use getFormat to produce custom formats with a variable number of decimal places based on how many were in the input string, and that works fine. Excel seems to display these on the 'format cell' dialog under Custom. But it also displays an explicit 'Decimal places' edit box where you can control this. My question. Does excel support data formats like "0.%" with the number of decimal places specified explicitly somewhere other than in the format string? It would seem much more efficient to work that way rather than to have to parse format strings to determine the number of decimal places. I guess this is another stupid question in the sense of 'why do you think we call it the Horrible Spreadsheet Format'? But can't hurt to ask. In the meantime, I'm also wondering whether Java-wise, it'd be more efficient to keep my own list of data type, #decimals combinations I've encountered so far scan that for formats. Or is it okay to just dynamically build a string with the right number of decimals each time and let getFormat take care of searching its list. In other words, are all those string concatenations expensive processing wise? Or does it all pale next to the parsing of the original strings to determine #decimals to begin with... Thanks, Rob -- View this message in context: http://www.nabble.com/number-of-decimal-places-in-data-formats-tp20671940p20671940.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]
