@Override
public void mediadown(HttpServletResponse response,ArrayList<media> med,HttpSession session) throws IOException {
// 1.创建一个workbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
// 2.在workbook中添加一个sheet,对应Excel中的一个sheet
HSSFSheet sheet = wb.createSheet("媒体信息表");
// 3.在sheet中添加表头第0行,老版本poi对excel行数列数有限制short
HSSFRow row = sheet.createRow((int) 0);
// 4.创建单元格,设置值表头,设置表头居中
HSSFCellStyle style = wb.createCellStyle();
// 居中格式
HSSFCell cell = row.createCell(0);
cell.setCellValue("id");
cell.setCellStyle(style);
cell = row.createCell(1);
cell.setCellValue("账户id");
cell.setCellStyle(style);
cell = row.createCell(2);
cell.setCellValue("媒体名称");
cell.setCellStyle(style);
cell = row.createCell(3);
cell.setCellValue("广告位id");
cell.setCellStyle(style);
cell = row.createCell(4);
cell.setCellValue("广告位名称");
cell.setCellStyle(style);
cell = row.createCell(5);
cell.setCellValue("操作系统");
cell.setCellStyle(style);
cell = row.createCell(6);
cell.setCellValue("广告位样式");
cell.setCellStyle(style);
cell = row.createCell(7);
cell.setCellValue("尺寸");
cell.setCellStyle(style);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
int i=0;
for(media hour:med){
row = sheet.createRow(i + 1);
row.createCell(0).setCellValue(hour.getId());
row.createCell(1).setCellValue(hour.getAccountid());
row.createCell(2).setCellValue(hour.getMedia());
row.createCell(3).setCellValue(hour.getApid());
row.createCell(4).setCellValue(hour.getAdname());
row.createCell(5).setCellValue(hour.getOs());
row.createCell(6).setCellValue(hour.getApstyle());
row.createCell(7).setCellValue(hour.getApsizie());
i++;
}
FileOutputStream out =new FileOutputStream("E:/test/媒体信息表.xls");
wb.write(out);
out.close();
这里的问题时可以下载 不报错但是名字不会变化,点击下载一次 第2次点击就不好使了不会自动命名 +1等 求解决,最好能探出下载框还不冲突,无语死了
}
最后会报这个错误getOutputStream() has already been called for this response
网上的方案我都是了不好使 我这里是后台,前台就一个下载2个字 ,后台里面 这些 方法都没有,网上说的方法 ,求大神帮忙
翻翻过去那场雪
慕标5832272
森栏
胡子哥哥
拉莫斯之舞
喵喔喔
HUWWW
慕村225694
红糖糍粑
繁星点点滴滴
相关分类