使用Apache POI在Excel单元格写号 [英] Write number in excel cells using Apache POI
本文介绍了使用Apache POI在Excel单元格写号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能写我的单元格中的全部价值与POI的帮助?
How can I write my full value in cell with help of poi ?
即。如果值为1000.000那么我怎么能不写后截断000这个充满价值。与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.
在我的情况下,只需要1000,但这是不正确的格式,适合我。
In my case, it only takes 1000 but this is not right format for me.
推荐答案
您必须设置其中获得存储这个数字的单元格的格式。例如:code:
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();
来源:<一个href=\"http://poi.apache.org/s$p$padsheet/quick-guide.html#DataFormats\">http://poi.apache.org/s$p$padsheet/quick-guide.html#DataFormats
这篇关于使用Apache POI在Excel单元格写号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文