java导出excel表格,话不多说,直接上代码!
/**
* 客户管理收入-导出报表
*/
@RequestMapping("/partnerExport")
public void export(List <PartnerIncomeDTO> list) throws IOException {
//这里需要传入你所需要导出的数据集合这里展示一下List,
try {
//创建Excel工具类。
ExcelUtil util = new ExcelUtil();
//得到与前端交互的返回对象(后面用来传入表格)
HttpServletResponse response = getResponse();
//给你导出的Excel取个名字
String fileName = "客户管理.xls";
//用来解决乱码问题
fileName = URLEncoder.encode(fileName, "UTF-8");
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
//创建IO输出流
OutputStream ouputStream = response.getOutputStream();
//你导出表格的每一列的列名
String[] headers = {"partnerUid", "custName","wechatNickname", "supPartnerUid", "regTime", "incomeAmtTotal", "availableBalance", "incomeAmount"};
//再创建一行,解释上面的列名
String[] headersCh = {"合伙人uid", "客户真实姓名", "微信昵称","引荐人uid", "注册时间", "收入总金额", "提现金额", "录入金额"};
//生成Excel并转换为Stream流
util.exportDataToExcel(list, headers, headersCh,"客户管理", ouputStream);
//创建Hss对象&#