java POI实现Excel单元格数据格式化

来源:互联网 发布:软件配置管理流程图 编辑:程序博客网 时间:2024/04/29 19:21
 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("E:\\standarcode\\workbook.xls");    wb.write(fileOut);    fileOut.close();

效果:


0 0
原创粉丝点击