Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write number in excel cells using Apache POI

Tags:

How can I write my full value in cell with help of poi ?

i.e. if value is 1000.000 then how can I write this full value without truncating 000 after "." with POI? means I want full value.

In my case, it only takes 1000 but this is not right format for me.

like image 839
Ravi Parmar Avatar asked Mar 17 '11 05:03

Ravi Parmar


People also ask

How do you change cell format to text in Excel using Java POI?

setDataFormat( fmt. getFormat("@")); cell. setCellStyle(cellStyle);


1 Answers

You have to set "Format" of the cell where this number is getting stored. Example code:

Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("format sheet"); CellStyle style; DataFormat format = wb.createDataFormat(); Row row; Cell cell; short rowNum = 0; short colNum = 0;  row = sheet.createRow(rowNum++); cell = row.createCell(colNum); cell.setCellValue(11111.25); style = wb.createCellStyle(); style.setDataFormat(format.getFormat("0.0")); cell.setCellStyle(style);  row = sheet.createRow(rowNum++); cell = row.createCell(colNum); cell.setCellValue(11111.25); style = wb.createCellStyle(); style.setDataFormat(format.getFormat("#,##0.0000")); cell.setCellStyle(style);  FileOutputStream fileOut = new FileOutputStream("workbook.xls"); wb.write(fileOut); fileOut.close(); 

Source : http://poi.apache.org/spreadsheet/quick-guide.html#DataFormats

like image 89
Shamit Verma Avatar answered Sep 28 '22 14:09

Shamit Verma