您必须设置要存储此数字的单元格的“格式”。示例代码:
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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)