SXSSFWorkbook wb = new SXSSFWorkbook();
Sheet sh = wb.createSheet();
int rowNum = 0;
XSSFDataFormat df = (XSSFDataFormat) wb.createDataFormat();
Row row = sh.createRow(rowNum++);
Cell cell = row.createCell(1);
cell.setCellValue(1.0);
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(df.getFormat("0"));
cell.setCellStyle(cellStyle); //自定义
Cell cell2 = row.createCell(2);
cell2.setCellValue(20000.0);
CellStyle cellStyle2 = wb.createCellStyle();
cellStyle2.setDataFormat(df.getFormat("#,#0"));
cell2.setCellStyle(cellStyle2); //货币
Cell cell3 = row.createCell(3);
CellStyle cellStyle3 = wb.createCellStyle();
cellStyle3.setDataFormat(df.getFormat("0"));
cell3.setCellValue(Double.parseDouble("3"));
cell3.setCellStyle(cellStyle3); //自定义
Cell cell4 = row.createCell(4);
CellStyle cellStyle4 = wb.createCellStyle();
cellStyle4.setDataFormat(df.getFormat("#,#0"));
cell4.setCellValue(Double.parseDouble("4"));
cell4.setCellStyle(cellStyle4); //货币
Cell cell5 = row.createCell(5);
cell5.setCellValue(5); //常规
Cell cell6 = row.createCell(6);
cell6.setCellValue("6"); //常规
Cell cell7 = row.createCell(7);
CellStyle cellStyle7 = wb.createCellStyle();
cellStyle7.setDataFormat(df.getFormat("@"));
cell7.setCellValue("7"); //文本
cell7.setCellStyle(cellStyle7);
//自定义格式但是带着¥
Cell cell8 = row.createCell(8);
CellStyle cellStyle8 = wb.createCellStyle();
cellStyle8.setDataFormat(df.getFormat("¥#,##0"));
cell8.setCellValue(800000);
cell8.setCellStyle(cellStyle8);
Cell cell9 = row.createCell(9);
cell9.setCellValue(0.9);
CellStyle cellStyle9 = wb.createCellStyle();
cellStyle9.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
cell9.setCellStyle(cellStyle9); //百分比
Cell cell10 = row.createCell(10);
cell10.setCellValue("0.10");
CellStyle cellStyle10 = wb.createCellStyle();
cellStyle10.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
cell10.setCellStyle(cellStyle10); //这种的直接输出0.9 不会乘以100%
//配置颜色
Cell cell11 = row.createCell(11);
cell11.setCellValue("xxxx");
CellStyle cellStyle11 = wb.createCellStyle();
cellStyle11.setDataFormat(df.getFormat("@"));
cellStyle11.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cellStyle11.setFillForegroundColor(IndexedColors.CORNFLOWER_BLUE.getIndex());
cell11.setCellStyle(cellStyle11); //这种的直接输出0.9 不会乘以100%
//颜色对照
//https://blog.csdn.net/oracle8090/article/details/106260459
/**
* 导出所以用到输出流
*参数为输出的地址
*/
FileOutputStream fout=new FileOutputStream("F:\\demo\\poi.xls");
wb.write(fout);//Workbook提供了write的方法
fout.close();//将输出流关闭