This works for me, is what I usually use:

pctCell = HSSFWorkbook_createCellStyle(book);
TempStr = new_String('0.00%');
NumFmt = HSSFDataFormat_getFormat(DataFmt: TempStr);
HSSFCellStyle_setDataFormat(pctCell: NumFmt);
HSSFCellStyle_setAlignment(pctCell: ALIGN_RIGHT);
HSSFCellStyle_setVerticalAlignment(pctCell:VERTICAL_CENTER) ;


Dennis Lovelady
http://www.linkedin.com/in/dennislovelady
--
"It is the difference of opinion that makes horse races."
-- Mark Twain
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-
bounces@xxxxxxxxxxxx] On Behalf Of sjl
Sent: Thursday, October 15, 2009 12:20 PM
To: midrange-l@xxxxxxxxxxxx
Subject: Re: Formatting a Cell as a Percent using POI.

Terry -

Another option is to create a simple spreadsheet with a single cell
that has
the correct % formatting, save it as an XML document, and examine how
Excel
does it by finding the formatting info in the XML doc...

- sjl

"Terry Anderson" <terrya@xxxxxxxxxxxx> wrote in message
news:mailman.6688.1255618783.1811.midrange-l@xxxxxxxxxxxxxxx
Greetings List,
I am creating an excel spread sheet using the Jakarta POI and am having
trouble getting a cell to format as percent. I set up the cell as
follows:

//
// Create a cell style for percents.
//

Percents = HSSFWorkbook_createCellStyle(book);

DataFmt = HSSFWorkbook_createDataFormat(book);
TempStr = new_String('0.00%');
PctFmt = HSSFDataFormat_getFormat(DataFmt: TempStr);
HSSFCellStyle_setDataFormat(Percents: PctFmt);

The problem is that when the program runs, I only get whole percents
and
anything under one percent shows as 0.00%.

In other words instead of getting 17.62% I get 17.00% and instead of
0.94% I get 0.00%.

Does any body have any ideas as to what I am doing wrong?


Terry Anderson
Programming Manager
Citation Corporation
Switchboard 1.251.867.5481 ext 212
Direct Line 1.251.809.2312
Fax 251.867.0525
Cell 1.251.363.4975


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



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.