java导出excel视频_java生成excel并下载功能

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

HttpServletRequest request = ServletActionContext.getRequest();

projectId =(long) Integer.parseInt(request.getParameter("projectList3"));

starttime = request.getParameter("startdate3");

endtime = request.getParameter("enddate3");

hcCustomers = saleLogService.selCustomer(projectId, starttime, endtime);

HSSFWorkbook workbook = new HSSFWorkbook();//在内存中创建一个表格文件

HSSFSheet sheet = workbook.createSheet("来访客户统计表");//在表格中创建一个标签

HSSFRow row = sheet.createRow(0);//创建行,作为标题行

row.createCell(0).setCellValue("客户姓名");

row.createCell(1).setCellValue("联系方式");

row.createCell(3).setCellValue("接待日期");

row.createCell(4).setCellValue("登记人员");

row.createCell(2).setCellValue("性别");

row.createCell(5).setCellValue("认知途径");

row.createCell(6).setCellValue("接待来源");

row.createCell(7).setCellValue("居住区域");

row.createCell(8).setCellValue("年龄段");

row.createCell(9).setCellValue("购房用途");

row.createCell(10).setCellValue("意向户型");

row.createCell(11).setCellValue("意向价格");

for (Map map:hcCustomers) {

HSSFRow dataRow = sheet.createRow(sheet.getLastRowNum()+1);//创建行,作为标题行

dataRow.createCell(0).setCellValue(map.get("CustomerName")+"");

dataRow.createCell(1).setCellValue(map.get("MobilePhone")+"");

dataRow.createCell(2).setCellValue(map.get("Sex")+"");

dataRow.createCell(5).setCellValue(map.get("CognitiveChannel")+"");

dataRow.createCell(7).setCellValue(map.get("ResidentialZone")+"");

dataRow.createCell(8).setCellValue(map.get("AgeGroup")+"");

dataRow.createCell(9).setCellValue(map.get("PurchasePurpose")+"");

dataRow.createCell(3).setCellValue(map.get("ReceptionTime")+"");

dataRow.createCell(6).setCellValue(map.get("ReceptionSource")+"");

dataRow.createCell(4).setCellValue(map.get("Salesman")+"");

dataRow.createCell(10).setCellValue(map.get("IntentionalChamber")+"");

dataRow.createCell(11).setCellValue(map.get("IntentionalPrice")+"");

}

/*ServletOutputStream outputStream = ServletActionContext.getResponse().getOutputStream();

ServletActionContext.getResponse().setContentType("application/vnd.ms-excel");

String filename = starttime+"-"+endtime+"来访客户统计表.xls";

String agent = ServletActionContext.getRequest().getHeader("User-Agent");

String finalFilename = FileUtils.encodeDownloadFilename(filename, agent);

ServletActionContext.getResponse().setHeader("content-disposition", "attchment;filename="+finalFilename);

workbook.write(outputStream);*/

HttpServletResponse response =ServletActionContext.getResponse();

String starString = starttime.substring(0,10);

String endString = endtime.substring(0,10);

OutputStream output = response.getOutputStream();

String FILE_OUTPUT_NAME ="来访客户统计表";

response.reset();

String name =starString+projectId+".xls";

OutputStream out = new FileOutputStream(name);

// 设置输出文档的头文件

FILE_OUTPUT_NAME = FileUtils.encodeDownloadFilename(FILE_OUTPUT_NAME, request.getHeader("user-agent"));

response.setContentType(request.getSession().getServletContext().getMimeType(FILE_OUTPUT_NAME));

response.setHeader("content-disposition", "attachment;filename=" + FILE_OUTPUT_NAME);

workbook.write(out);

response.setHeader("Content-disposition","attachment; filename="+starString+"-"+endString+"-"+projectId+".xls");

response.setContentType("application/octet-stream");//告诉浏览器输出内容为流

workbook.write(output);

return NONE;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值