SXSSFWorkbook poi导出技术的简单使用

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();//将输出流关闭

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值