zoukankan      html  css  js  c++  java
  • poi导出excel

    // 创建一个Excel文件
    HSSFWorkbook workbook = new HSSFWorkbook();
    // 创建一个工作表
    HSSFSheet sheet = workbook.createSheet("销售订单列表");
    // 添加表头行
    HSSFRow hssfRow = sheet.createRow(0);
    // 设置单元格格式居中
    HSSFCellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    
    // 添加表头内容
    HSSFCell headCell = hssfRow.createCell(0);
    headCell.setCellValue("订单编号");
    headCell.setCellStyle(cellStyle);
    
    headCell = hssfRow.createCell(1);
    headCell.setCellValue("产品编号");
    headCell.setCellStyle(cellStyle);
    
    headCell = hssfRow.createCell(2);
    headCell.setCellValue("销售员编号");
    headCell.setCellStyle(cellStyle);
    
    // 添加数据内容
    for (int i = 0; i < xsLists.size(); i++) {
    hssfRow = sheet.createRow((int) i + 1);
    XSList xsList = xsLists.get(i);
    
    // 创建单元格,并设置值
    HSSFCell cell = hssfRow.createCell(0);
    cell.setCellValue(xsList.getSaleno());
    cell.setCellStyle(cellStyle);
    
    cell = hssfRow.createCell(1);
    cell.setCellValue(xsList.getProductno());
    cell.setCellStyle(cellStyle);
    
    cell = hssfRow.createCell(2);
    cell.setCellValue(xsList.getStaffno());
    cell.setCellStyle(cellStyle);
    }
    
    // 保存Excel文件
    try {
    OutputStream outputStream = new FileOutputStream("E:/XSList.xls");
    workbook.write(outputStream);
    outputStream.close();
    } catch (Exception e) {
    e.printStackTrace();
    }
    

      

  • 相关阅读:
    [loj3364]植物比较
    [loj3366]嘉年华奖券
    [atARC105F]Lights Out on Connected Graph
    [atARC105D]Let's Play Nim
    [atARC058F]Lroha Loves Strings
    [loj3347]有趣的旅途
    [atAGC001F]Wide Swap
    [cf1392I]Kevin and Grid
    [loj3340]命运
    [loj3046]语言
  • 原文地址:https://www.cnblogs.com/ZhangHaiBK/p/8988649.html
Copyright © 2011-2022 走看看