Morning Luke,

How are you getting on with the rest of the code for this project?

With regard to formatting the cells appearance, it is really a two stage
process. The first thing you need to do is to create a CellStyle object, set
the data format of this object and then apply the style to the cell. The
basic approach goes a little like this;

CellStyle cellStyle = null;
CreationHelper ch = workbook.getCreationHelper();

cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat(ch.createDataFormat().getFormat("0.00"));
cellStyle.setAlignment(CellStyle.ALIGN_RIGHT);

and then once you have the style you can simple apply it to a cell as you
create it;

cell.setCellStyle(cellStyle);

.

The code above targets the SS classes so as to work wwith both binary and
OOXML based workbooks. If your code targets just one or the other type, then
you will need to modify it slightly - the CreationHelper will likely be
un-necessary for example - but it is a good place to start.

Have you solved the issue of sorting the data once you have read it from
your source workbooks and prior to outputting it to the destination one yet?
If not, think about creating a class to hold the data from a single row.
This class might implement the Comparable interface and override the
compareTo() method then, when you have stored lots of instances into a
collection suach as an ArrayList, you can call the Collections.sort() method
to sort the data for you.

Yours

Mark B


Luke_Devon wrote:
> 
> Hi Dave
> 
> I am going to create a single XLS file from set of (Series of ) excel data
> files. But for the the file which i wanted generate , must be having a
> column with different CELL formating which must be Number and 2 decimal
> places.Other data fileds always default (General).
> But I could not understand what I can extract from your reply  . Can you
> please help me? 
> 
> Thanks
> Luke
> 
> 
> 
> ________________________________
> From: David Fisher <[email protected]>
> To: POI Users List <[email protected]>
> Sent: Tuesday, June 15, 2010 21:45:42
> Subject: Re: Cell Formatting
> 
>> Hi
>> 
>> I wanted to assign Cell formatting for a particular field which is
>> supposed to handle numeric values.
>> 
>> For example :
>> 
>> In the column D , I have a filed called Total. This entire column i
>> wanted format as "Number" with 2 decimal places.
>> 
>> Can some body help me on this with an example?
> 
> Try looking here:
> http://poi.apache.org/spreadsheet/quick-guide.html#DataFormats
> 
> Regards,
> Dave
> 
> 
>> 
>> Thanks in advance.
>> Luke
>> 
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Cell-Formatting-tp28890884p28910956.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]

Reply via email to