easyPoi本来是挺好用的,和一个java实体类关联,操控实体数组就能写出来一个Excel文件,但在实际用途中我们需要为一些特殊的单元格做一些调整,让人看的舒服一些,也更加突出。
要达到这种效果。先加上maven
cn.afterturn
easypoi-base
4.0.0
cn.afterturn
easypoi-web
4.0.0
cn.afterturn
easypoi-annotation
4.0.0
首先是easyPoi的工具类,复制粘贴就好。
package com.demo.utils;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
/**
* 导入导出公用方法
*/
public class PoiUtils {
public static void exportExcel(List> list, String title, String sheetName, Class> pojoClass, String fileName, boolean isCreateHeader, HttpServletResponse response) {
ExportParams exportParams = new ExportParams(title, sheetName);
exportParams.setCreateHeadRows(isCreateHeader);
defaultExport(list, pojoClass, fileName, response, exportParams);
}
public static void exportExcel(List> list, String title, String sheetName, Class> pojoClass, String fileName, HttpServlet