Thank you very much for your reply Christopher!

I was populating data as a String.  I had to
convert it to a number before populating the cell.

all my formats are working now.



Christophe Charles wrote:
> 
> You can try this :
> 
>  HSSFDataFormat dataFormat = wbook.createDataFormat();
> shot indexFormat = dataFormat.getFormat("$#,##0.00");
> HSSFCellStyle style = wbook.createCellStyle();
> style.setDataFormat(indexFormat);
> 
> cell.setCellValue(s);
> cell.setCellStyle(style);
> 
> 
> 
> 
> 
> 
> 
> 
> 2009/7/28 dhiruster <[email protected]>:
>>
>> Well here is snippet of the code.
>>
>> Workbook wb = new HSSFWorkbook();
>> Sheet   sheet = wb.createSheet("Business");
>> DataFormat df = wb.createDataFormat();
>> CellStyle style =wb.createCellStyle();
>> style.setAlignment(CellStyle.ALIGN_RIGHT);
>>        style.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index);
>>        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
>>        style.setDataFormat(df.getFormat("$#,##0.00"));
>>
>> // more of similar code with different formats
>> // create rows and cells - set cell value and cell style
>> // s is data in String format
>>
>> cell.setCellValue(s);
>> cell.setCellStyle(style);
>>
>> //set column width below and write the file
>>
>>  for (int i = 0; i < headerList.size(); i++) {
>>                        if (i == 0){
>>                                sheet.setColumnWidth(i, 256*33);
>>                        } else {
>>                                sheet.setColumnWidth(i, 256*15);
>>                        }
>>                }
>>
>>
>>          String file = "C:\\workbook.xls";
>>          try {
>>                  FileOutputStream out = new FileOutputStream(file);
>>                  wb.write(out);
>>                  out.close();
>>          } catch (FileNotFoundException e) {
>>                  // TODO Auto-generated catch block
>>                  e.printStackTrace();
>>          } catch (IOException e) {
>>                  // TODO Auto-generated catch block
>>                  e.printStackTrace();
>>          }
>>
>>
>> Christophe Charles wrote:
>>>
>>> Hello Dhiruster,
>>>
>>> Can we have some piece of code ?
>>>
>>> thx
>>>
>>> 2009/7/28 dhiruster <[email protected]>:
>>>>
>>>> Hi,
>>>> I am new to apache poi and excel.  We have a user requirement to export
>>>> data
>>>> to excel from a grid.
>>>>
>>>> I am using poi-3.5-beta6.
>>>>
>>>> I am using  dataformat e.g.
>>>> style.setDataFormat(format.getFormat("$#,##0.00"));
>>>> and applying to each cell.
>>>> When I bring up the spreadsheet the data is still in the original
>>>> format.
>>>> The format is only applied if I select the cell and hit enter.
>>>>
>>>> I would like to see the format already applied to all cells when I open
>>>> the spreadsheet.  How do I go about doing that?
>>>>
>>>> Thanks in advance.
>>>>
>>>> Dhiruster
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Applying-format-tp24701685p24701685.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]
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Applying-format-tp24701685p24703463.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]
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Applying-format-tp24701685p24704141.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