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;
總結
以上是生活随笔為你收集整理的java生成excel_java生成excel并下载功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python tuple list_草根
- 下一篇: 调用接口的方法 java_java调用接