叮當(dāng)貓咪
2018-12-06 14:01:15
?? ?@Override?? ?public void mediadown(HttpServletResponse response,ArrayList<media> med,HttpSession session) throws IOException {?? ??? ?// 1.創(chuàng)建一個(gè)workbook,對(duì)應(yīng)一個(gè)Excel文件?? ??? ?HSSFWorkbook wb = new HSSFWorkbook();?? ??? ?// 2.在workbook中添加一個(gè)sheet,對(duì)應(yīng)Excel中的一個(gè)sheet?? ??? ?HSSFSheet sheet = wb.createSheet("媒體信息表");?? ??? ?// 3.在sheet中添加表頭第0行,老版本poi對(duì)excel行數(shù)列數(shù)有限制short?? ??? ?HSSFRow row = sheet.createRow((int) 0);?? ??? ?// 4.創(chuàng)建單元格,設(shè)置值表頭,設(shè)置表頭居中?? ??? ?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("操作系統(tǒng)");?? ??? ?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();
這里的問題時(shí)可以下載 不報(bào)錯(cuò)但是名字不會(huì)變化,點(diǎn)擊下載一次 第2次點(diǎn)擊就不好使了不會(huì)自動(dòng)命名 +1等 求解決,最好能探出下載框還不沖突,無語(yǔ)死了?? ?}
?
?
?
?
?
最后會(huì)報(bào)這個(gè)錯(cuò)誤getOutputStream() has already been called for this response
網(wǎng)上的方案我都是了不好使 ?我這里是后臺(tái),前臺(tái)就一個(gè)下載2個(gè)字 ?,后臺(tái)里面 這些 方法都沒有,網(wǎng)上說的方法 ,求大神幫忙
21 回答

慕標(biāo)5832272
TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊
是的 下載 的時(shí)候就有沖突,但是不影響程序 ,不過控制臺(tái)報(bào)錯(cuò) 網(wǎng)上的方法都是了 還是不好時(shí) 擦擦擦求解

喵喔喔
TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊
- out.clear();??
- out?=?pageContext.pushBody();?
- 這兩句話應(yīng)該放在哪里啊 ,為啥我的下載類? 里面out 沒有這兩個(gè)方法? 咋弄啊 求解

HUWWW
TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊
@skateweb: 你用記事本打開.cs后綴的文件,然后找到導(dǎo)出的代碼 ?把我上面那個(gè)類新建一個(gè)幫助類

慕村225694
TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊
@skateweb: ? ?我的意思是,你換這種方案看看會(huì)不會(huì)有這個(gè)異常... 這個(gè)異常我不知道 ?

繁星點(diǎn)點(diǎn)滴滴
TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊
@skateweb: 我覺得很簡(jiǎn)單啊。。。 ?你想辦法弄一個(gè)DataTable ?其他的就直接調(diào)用
添加回答
舉報(bào)
0/150
提交
取消