[英]Write number in excel cells using Apache POI
如何在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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.