zoukankan      html  css  js  c++  java
  • java导出Excel数据大可以用多个sheet页存数据

    package cn.com.sinosoft.boot.webservice;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.OutputStream;


    @RunWith(SpringRunner.class)
    @SpringBootTest
    @Slf4j
    public class WebServiceAxisClient {

    @Test
    public void run7() {
    try {
    HSSFWorkbook wb = new HSSFWorkbook();
    //写入的路径到具体xls
    File savedFile = new File("E:\anti_money\111.xls");
    OutputStream output = new FileOutputStream(savedFile);
    //查询数据LpfMLmRiskAppBPojo表示实体类,lpfMLmRiskAppBDao表示与数据库查询的dao层
            List<LpfMLmRiskAppBPojo> list = lpfMLmRiskAppBDao.queryAll();
    int totle = list.size();// 获取List集合的size
    int mus = 5;// :excel表格一个工作表可以存储5条)
    int avg = totle / mus;
    for (int i = 0; i < avg + 1; i++) {
          //sheet页的名称

    HSSFSheet sheet = wb.createSheet("信息" + (i + 1));
    HSSFRow row = sheet.createRow(0);
    // 第一行标题
    String[] head = new String[]{"险种编码", "险种名称"};
    int headInt = 0;
    for (String title : head) {
    row.createCell(headInt++).setCellValue(title);
    }
    int num = i * mus;
    int index = 0;
    int rowInt = 1;
    for (int m = num; m < list.size(); m++) {
    if (index == mus) {// 判断index == mus的时候跳出当前for循环
    break;
    }
    LpfMLmRiskAppBPojo actualReturnDetial = list.get(m);
    // 每列对应的字段
    row = sheet.createRow(rowInt++); // 创建行
    row.createCell(0).setCellValue(actualReturnDetial.getRiskCode());
    row.createCell(1).setCellValue(actualReturnDetial.getRiskName());

    index++;
    }
    }
    wb.write(output);
    output.close();

    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    }
  • 相关阅读:
    消息队列在VB.NET数据库开发中的应用
    PO: Tips and useful Query
    PO 收料SQL
    计划采购订单
    检查订单是否有退货
    采购订单关闭之PL/SQL实现方法
    库存核心业务(库存管理 库存事务处理)
    采购管理核心流程
    Oracle EBS: 获取PO审批人名字
    ORACLE EBS AP发票到付款的数据流
  • 原文地址:https://www.cnblogs.com/lwla/p/13716511.html
Copyright © 2011-2022 走看看