You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Srinadh Karumuri <sk...@bbn.com> on 2004/03/09 20:16:57 UTC

Re: DataFormat for "0.0" is not working in Excel when created from Template

After downloading the 2.0 Final source and debugging I found that it 
happens only when the format is already there in the Excel sheet as user 
defined "Custom" format.

I went to my template file and did
         Format->Cells...->Category (Custom)
I was able to see "0.0" at the bottom of the list as I used this earlier in 
the template.
I deleted this user defined Custom format as this is not an in built Custom 
format.

Now it works fine and I am all set.

If you are wondering what the problem is, let me rephrase it:

Bug:
         DataFormat will not work for the user defined Custom formats in 
the Excel template files.

Workaround:
         Delete this user defined Custom format from the template and it 
will all work fine.

-Srinadh

At 12:32 PM 3/9/2004, Srinadh Karumuri wrote:
>I am trying to show the numbers with one decimal and I couldn't get it to 
>work with templates.
>
>BTW, this code works perfectly if  I do not use template and create new 
>Excel file from scratch and it also works fine if I set the format  to "0" 
>or "0.00".
>
>Here is my sample data:
>55
>54.5
>
>I want to show them as below:
>55.0
>54.5
>
>Here is the complete working code to reporduce this probelm:
>(I just modified the example from POI site)
>
>POIFSFileSystem fs = new POIFSFileSystem(new 
>FileInputStream("workbook1.xls"));
>HSSFWorkbook wb = new HSSFWorkbook(fs);
>
>HSSFSheet sheet = wb.createSheet("format sheet");
>HSSFCellStyle style;
>HSSFDataFormat format = wb.createDataFormat();
>HSSFRow row;
>HSSFCell cell;
>short rowNum = 0;
>short colNum = 0;
>
>row = sheet.createRow(rowNum++);
>cell = row.createCell(colNum);
>cell.setCellValue(111.256);
>style = wb.createCellStyle();
>style.setDataFormat(format.getFormat("0.0"));
>cell.setCellStyle(style);
>
>FileOutputStream fileOut = new FileOutputStream("workbook2.xls");
>wb.write(fileOut);
>fileOut.close();
>
>
>Thanks for any help,
>Sri
>


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-user-help@jakarta.apache.org