java导出Excel

package cn.com.yitong.fcrm.workbench.service;

import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.com.yitong.fcrm.base.ExcelUtil;
import cn.com.yitong.framework.core.util.BeanHelper;

/**
* 融e理财购买记录导出excel
*/

public class ExcelPayMoneyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public ExcelPayMoneyServlet() {
super();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ReleasefinancialService service = BeanHelper.get("releasefinancialService", ReleasefinancialService.class);
String product_kind = request.getParameter("product_kind");
List> list = service.queryPayExport(product_kind);
//导出excel
LinkedHashMap fieldMap = new LinkedHashMap();
fieldMap.put("BORROW_NO", "编号");
fieldMap.put("BORROW_NAME", "名称");
fieldMap.put("PRODUCT_NAME", "产品名称");
fieldMap.put("BORROW_RATE", "利率");
fieldMap.put("BORROW_AMOUNT", "金额");
fieldMap.put("BORROW_TERM", "期限");
fieldMap.put("GIVEOUT_BANKCARDNO", "账号");
fieldMap.put("GIVEOUT_AMOUNT", "金额");
fieldMap.put("GIVEOUT_DATE", "日期");
fieldMap.put("GIVEOUT_TIME", "时间");
String sheetName="记录";
int sheetSize = list.size();
OutputStream out = null;
out = response.getOutputStream();
response.reset();
String filename = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()).toString();
response.setHeader("Content-disposition", "attachment;filename="+filename+".xls");
response.setContentType("application/msexcel");
try {
ExcelUtil.listToExcel (list,fieldMap,sheetName,sheetSize,out);
} catch (Exception e) {
e.printStackTrace();
}
out.close();
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

}



需要在web.xml配置如下信息:
ExcelPayMoneyServlet
cn.com.yitong.fcrm.workbench.service.ExcelPayMoneyServlet
ExcelPayMoneyServlet
/ExcelPayMoneyServlet

你可能感兴趣的:(java导出Excel,java,导出Excel)