package util;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.springframework.util.StringUtils;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Excel工具类
*
* @Author admin
* @date 2018/9/26
*/
public class ExcelUtils {
/**
* @param request
* @param response
* @param fileName 文件名
* @param projects 对象集合
* @param columnNames 列名
* @param keys map中的key
* @throws IOException
*/
public static void exportExcel(HttpServletRequest request, HttpServletResponse response, String fileName, List> projects, String[] columnNames, String[] keys) throws IOException {
//封装对象属性
List
使用:
List list = raiseProjectMemberParticipateService.queryMemberParticipateList();
// 列名
String columnNames[] = {"会员手机号", "产品编码", "产品份额", "退回份额", "项目名称", "参与产品名称", "参与状态",
"参与时间","修改时间","修改人"};
// map中的key
String keys[] = {"phoneCode", "prodCode", "number", "updateNumber", "projectName", "prodName", "participateStatusDesc",
"crtDate", "modDate", "modOper"};
try {
ExcelUtils.exportExcel(request, response, fileName, list, columnNames, keys);
} catch (IOException e) {
logger.error("导出项目参与列表Excel失败!{}", e);
}
不用返回值,直接以流的形式返回