如何使用POI将完整的值写入单元格?
例如,如果值为1000.000,则如何在不截断小数点后面的000的情况下写入完整值? 我想要完整的值。
在我的情况下,它只能够接受1000,但这对我来说不是正确的格式。
如何使用POI将完整的值写入单元格?
例如,如果值为1000.000,则如何在不截断小数点后面的000的情况下写入完整值? 我想要完整的值。
在我的情况下,它只能够接受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