使用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 的情况下写入这个完整值.与兴趣点?意味着我想要全部价值.
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.
推荐答案
您必须设置存储此数字的单元格的格式".示例代码:
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();
来源:http://poi.apache.org/spreadsheet/quick-guide.html#DataFormats
这篇关于使用Apache POI在excel单元格中写入数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文