在使用Apache POI的Excel单元格中编写数字

如何在poi的帮助下在单元格中写下我的全部价值?

即如果值是1000.000,那么我怎样才能写这个完整的值,而不会截断“000”后的000。 有POI? 意味着我想要充分的价值。

在我的情况下,只需要1000,但这是不正确的格式。

您必须设置存储此号码的单元格的“格式”。 示例代码:

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