使用poi实现动态合并单元格导出excel

使用poi进行动态合并单元格,

参考博客:https://blog.csdn.net/yuan890720/article/details/52368366

根据卖家公司字段匹配导出结果样式:

在这里插入图片描述

代码如下

package test;

import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**

  • Created by LH on 2019/8/20 9:57
    */
    public class Test2 {

    // 日志
    private static Logger log = Logger.getLogger(Test2.class
    .getName());

    /**

    • 判断文件是否存在
    • @param path
    • @return
      */
      public static boolean checkFile(String path) {
      File file = new File(path);
      if (file.exists()) {
      return true;
      } else {
      return false;
      }
      }

    /**

    • 建立订单查询ExcelFile

    • @param excelPath

    • @return
      */
      public static boolean createExcelFile(String excelPath,List info) {

      /**

      • 新增列:买家公司交易金额
      • NorthLee

      */
      HSSFWorkbook workbook = new HSSFWorkbook();
      HSSFSheet sheet = workbook.createSheet(“实际成交订单”);

      HSSFCellStyle style = workbook.createCellStyle();
      HSSFFont font = workbook.createFont();
      font.setFontHeightInPoints((short) 12);//字号
      font.setFontName(“宋体”);
      font.setBold(true); //粗体

      style.setFont(font);
      style.setWrapText(true);

      // 标题行
      HSSFRow row = sheet.createRow(0);
      // 行高
      row.setHeight((short) (20*20));
      // 列数
      HSSFCell cell0 = row.createCell(0);
      cell0.setCellStyle(style);
      cell0.setCellValue(“订单号”);

      HSSFCell cell1 = row.createCell(1);
      cell1.setCellStyle(style);
      cell1.setCellValue(“货物标题”);

      HSSFCell cell2 = row.createCell(2);
      cell2.setCellStyle(style);
      cell2.setCellValue(“支付价格”);

      HSSFCell cell3 = row.createCell(3);
      cell3.setCellStyle(style);
      cell3.setCellValue(“批付价格”);

      HSSFCell cell4 = row.createCell(4);
      cell4.setCellStyle(style);
      cell4.setCellValue(“卖家真实姓名”);

      HSSFCell cell5 = row.createCell(5);
      cell5.setCellStyle(style);
      cell5.setCellValue(“卖家公司”);

      HSSFCell cell6 = row.createCell(6);
      cell6.setCellStyle(style);
      cell6.setCellValue(“买家公司交易总额”);

      HSSFCell cell7 = row.createCell(7);
      cell7.setCellStyle(style);
      cell7.setCellValue(“买家真实姓名”);

      HSSFCell cell8 = row.createCell(8);
      cell8.setCellStyle(style);
      cell8.setCellValue(“买家公司”);

      HSSFCell cell9 = row.createCell(9);
      cell9.setCellStyle(style);
      cell9.setCellValue(“货运地址”);

      HSSFCell cell10 = row.createCell(10);
      cell10.setCellStyle(style);
      cell10.setCellValue(“买家联系方式1”);

      HSSFCell cell11 = row.createCell(11);
      cell11.setCellStyle(style);
      cell11.setCellValue(“买家联系方式2”);

      HSSFCell cell12 = row.createCell(12);
      cell12.setCellStyle(style);
      cell12.setCellValue(“货运方式”);

      HSSFCell cell13 = row.createCell(13);
      cell13.setCellStyle(style);
      cell13.setCellValue(“货运联系人”);

      HSSFCell cell14 = row.createCell(14);
      cell14.setCellStyle(style);
      cell14.setCellValue(“货运车牌号”);

      HSSFCell cell15 = row.createCell(15);<

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值