使用poi进行动态合并单元格,
参考博客:https://blog.youkuaiyun.com/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);<