导出excel封装类

action中调用方法

private void exportList(List numberList,String numType, HttpServletResponse response) throws Exception {

List excellist = new ArrayList();//数据列表
String docName = "exp189CDMA.xls";
String sheetname ="";
ExcelUtil excelutil = new ExcelUtil();
try {
List headerlist = new ArrayList();
//表头
headFont(headerlist);
headerList(headerlist,numType);
excellist.add(headerlist);//加入表头
if (numberList.size() > 0) {
for (int i = 0; i < numberList.size(); i++) {
Map map =new HashMap();
if(numberList.get(i) instanceof Map){
map = (Map)numberList.get(i);
List lineDataList = new ArrayList();
lineDataList.add(map.get("province"));
lineDataList.add(map.get("localname"));
lineDataList.add(map.get("telCode"));
for(int k=0;k<=9;k++){
lineDataList.add(map.get("hcode"+k));
}
excellist.add(lineDataList);
}
}
}

} catch (Exception e) {
throw e;
}

response.reset();
response.setCharacterEncoding("UTF-8");
docName = URLEncoder.encode(docName, "UTF-8");
response.setContentType("application/x-msdownload;charset=UTF-8");
response.setHeader("Content-disposition", "attachment; filename="
+ new String(docName.getBytes("UTF-8"), "UTF-8"));

OutputStream outStream = response.getOutputStream();
excelutil.getWorkbook(excellist, sheetname).write(outStream);
}

/**
* 导出EXCEL
*
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
* @throws Exception
*/
private void exportList(List[] numberList,String[] reportSel, HttpServletResponse response) throws Exception {

int length = reportSel.length;
String docName = "exp189CDMA.xls";
List[] excellist = new ArrayList[length];//数据列表
String[] sheetnames = new String[length];
for(int i=0;i<length;i++){
sheetnames[i] =reportSel[i];
}
if(StringUtils.isEmpty("")){}
ExcelUtil excelutil = new ExcelUtil();
for(int n = 0;n<reportSel.length;n++){
String selValue = reportSel[n];
if("189H码新增表".equals(selValue)){
try {
//新增表

excellist[n] = new ArrayList();
List headerlist = new ArrayList();
headFont(headerlist);
//头部号码
headerList(headerlist,"189");
excellist[n].add(headerlist);//加入表头
List list1 = numberList[n];
if (list1.size() > 0) {
for (int i = 0; i < list1.size(); i++) {
Num189CDMAExpVO vo = (Num189CDMAExpVO)list1.get(i);
List lineDataList = new ArrayList();
lineDataList.add(vo.getProvince());
excellist[n].add(lineDataList);
}
}

} catch (Exception e) {
throw e;
}
}

response.reset();
response.setCharacterEncoding("UTF-8");
docName = URLEncoder.encode(docName, "UTF-8");
response.setContentType("application/x-msdownload;charset=UTF-8");
response.setHeader("Content-disposition", "attachment; filename="
+ new String(docName.getBytes("UTF-8"), "UTF-8"));

OutputStream outStream = response.getOutputStream();
excelutil.getWorkbook(excellist, sheetnames).write(outStream);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值