本文與另一篇文章關(guān)聯(lián):
其中:
String accountDate? 入?yún)ⅲㄈ掌冢?/p>
AccountInfoEntityResp accountInfoEntityResp? 導(dǎo)出的xml報文內(nèi)容(轉(zhuǎn)換成obj對象)
xml報文解析見另一篇:xml報文解析
HttpServletRequest request?
HttpServletResponse response?
主要核心代碼如下:
/**
? ? * 導(dǎo)出exc方法
? ? */
? ? public void exportExcel(String accountDate, AccountInfoEntityResp accountInfoEntityResp,HttpServletRequest request,HttpServletResponse response) throws IOException {
? ? ? ? // 聲明一個工作簿
? ? ? ? HSSFWorkbook wb = new HSSFWorkbook();
? ? ? ? // 聲明一個工作單并命名
? ? ? ? HSSFSheet sheet = wb.createSheet("accountInfo");
? ? ? ? // 創(chuàng)建標題樣式
? ? ? ? HSSFCellStyle headerStyle = (HSSFCellStyle) wb.createCellStyle();
? ? ? ? headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中
? ? ? ? headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直對齊居中
? ? ? ? headerStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);//下邊框
? ? ? ? headerStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左邊框
? ? ? ? headerStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上邊框
? ? ? ? headerStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右邊框
? ? ? ? //創(chuàng)建字體
? ? ? ? HSSFFont header_Font = (HSSFFont) wb.createFont();
? ? ? ? header_Font.setFontName("微軟雅黑");
? ? ? ? header_Font.setFontHeightInPoints((short) 15);
? ? ? ? headerStyle.setFont(header_Font);
? ? ? ? // 創(chuàng)建單元格樣式
? ? ? ? HSSFCellStyle cell_Style = (HSSFCellStyle) wb.createCellStyle();// 設(shè)置字體樣式
? ? ? ? cell_Style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
? ? ? ? cell_Style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直對齊居中
? ? ? ? cell_Style.setBorderBottom(HSSFCellStyle.BORDER_THIN);//下邊框
? ? ? ? cell_Style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左邊框
? ? ? ? cell_Style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上邊框
? ? ? ? cell_Style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右邊框
? ? ? ? cell_Style.setWrapText(true); // 設(shè)置為自動換行
? ? ? ? HSSFFont cell_Font = (HSSFFont) wb.createFont();
? ? ? ? cell_Font.setFontName("微軟雅黑");
? ? ? ? cell_Font.setFontHeightInPoints((short) 12);
? ? ? ? cell_Style.setFont(cell_Font);
? ? ? ? //創(chuàng)建自由樣式
? ? ? ? HSSFCellStyle free_Style = (HSSFCellStyle) wb.createCellStyle();// 設(shè)置字體樣式
? ? ? ? free_Style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
? ? ? ? free_Style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
? ? ? ? HSSFFont free_Font = (HSSFFont) wb.createFont();
? ? ? ? free_Font.setFontName("微軟雅黑");
? ? ? ? free_Font.setFontHeightInPoints((short) 12);
? ? ? ? free_Style.setFont(free_Font);
? ? ? ? //【結(jié)算場次列表】單元格行數(shù):SttlList->SttlInf集合size大小+1(標題行)
? ? ? ? int sttlInfCount = accountInfoEntityResp.getSttlList().size()+1;
? ? ? ? //【批次列表】單元格行數(shù):SttlList->SttlInf->BatchList->BatchInf的集合大小+1(標題行)
? ? ? ? int batchInfCount = 1;
? ? ? ? //【分項列表】單元格行數(shù):SttlList->SttlInf->BatchList->BatchInf->SubItemList->SubItemInf的集合大小+1(標題行)
? ? ? ? int subItemInfCount = 0;
? ? ? ? if(accountInfoEntityResp.getSttlList() != null){
? ? ? ? ? ? for(int i = 0; i< accountInfoEntityResp.getSttlList().size() ;i++){
? ? ? ? ? ? ? ? //批次列表大小
? ? ? ? ? ? ? ? batchInfCount = batchInfCount + accountInfoEntityResp.getSttlList().get(i).getBatchList().size();
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? //結(jié)算場次列表+批次列表+分項列表 =明細單元格行數(shù)
? ? ? ? int detailCount = sttlInfCount + batchInfCount + subItemInfCount ;
? ? ? ? //1.1創(chuàng)建合并單元格對象
? ? ? ? //頭部"賬務(wù)日期"
? ? ? ? CellRangeAddress callRangeAddress = new CellRangeAddress(0,0,0,7);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? //第二行
? ? ? ? CellRangeAddress callRangeAddress1 = new CellRangeAddress(1,1,0,1);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? CellRangeAddress callRangeAddress1_2 = new CellRangeAddress(1,1,2,3);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? CellRangeAddress callRangeAddress1_3 = new CellRangeAddress(1,1,4,5);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? CellRangeAddress callRangeAddress1_4 = new CellRangeAddress(1,1,6,7);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? //第三行
? ? ? ? CellRangeAddress callRangeAddress2 = new CellRangeAddress(2,2,0,1);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? CellRangeAddress callRangeAddress2_3 = new CellRangeAddress(2,2,2,3);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? CellRangeAddress callRangeAddress2_4 = new CellRangeAddress(2,2,4,5);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? CellRangeAddress callRangeAddress2_5 = new CellRangeAddress(2,2,6,7);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? //明細
? ? ? ? CellRangeAddress callRangeAddress3 = new CellRangeAddress(3,3,0,7);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? //結(jié)算場次列表
? ? ? ? CellRangeAddress callRangeAddress4 = new CellRangeAddress(4,4,0,7);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? //批次列表
? ? ? ? CellRangeAddress callRangeAddress5 = new CellRangeAddress(sttlInfCount+4+1,sttlInfCount+4+1,0,7);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? //分項列表
? ? ? ? CellRangeAddress callRangeAddress6 = new CellRangeAddress(sttlInfCount+4+1+batchInfCount+1,sttlInfCount+4+1+batchInfCount+1,0,7);//起始行,結(jié)束行,起始列,結(jié)束列
? ? ? ? //2.1加載合并單元格對象
? ? ? ? sheet.addMergedRegion(callRangeAddress);
? ? ? ? sheet.addMergedRegion(callRangeAddress1);
? ? ? ? sheet.addMergedRegion(callRangeAddress1_2);
? ? ? ? sheet.addMergedRegion(callRangeAddress1_3);
? ? ? ? sheet.addMergedRegion(callRangeAddress1_4);
? ? ? ? sheet.addMergedRegion(callRangeAddress2);
? ? ? ? sheet.addMergedRegion(callRangeAddress2_3);
? ? ? ? sheet.addMergedRegion(callRangeAddress2_4);
? ? ? ? sheet.addMergedRegion(callRangeAddress2_5);
? ? ? ? sheet.addMergedRegion(callRangeAddress3);
? ? ? ? sheet.addMergedRegion(callRangeAddress4);
? ? ? ? sheet.addMergedRegion(callRangeAddress5);
? ? ? ? sheet.addMergedRegion(callRangeAddress6);
? ? ? ? //3.1創(chuàng)建頭標題行;并且設(shè)置頭標題
? ? ? ? HSSFRow row = sheet.createRow(0);
? ? ? ? HSSFCell cell = row.createCell(0);
? ? ? ? //加載單元格樣式
? ? ? ? cell.setCellStyle(headerStyle);
? ? ? ? cell.setCellValue("財務(wù)日期:"+accountDate);
? ? ? ? //4.1創(chuàng)建第二行
? ? ? ? HSSFRow rower = sheet.createRow(1);
? ? ? ? //結(jié)算總筆數(shù)
? ? ? ? HSSFCell celler_1 = rower.createCell(0);
? ? ? ? //借方金額
? ? ? ? HSSFCell celler_2 = rower.createCell(2);
? ? ? ? //貸方金額
? ? ? ? HSSFCell celler_3 = rower.createCell(4);
? ? ? ? //結(jié)算場次明細
? ? ? ? HSSFCell celler_4 = rower.createCell(6);
? ? ? ? //加載單元格樣式
? ? ? ? celler_1.setCellStyle(cell_Style);
? ? ? ? celler_1.setCellValue("結(jié)算總筆數(shù)");
? ? ? ? celler_2.setCellStyle(cell_Style);
? ? ? ? celler_2.setCellValue("借方金額");
? ? ? ? celler_3.setCellStyle(cell_Style);
? ? ? ? celler_3.setCellValue("貸方金額");
? ? ? ? celler_4.setCellStyle(cell_Style);
? ? ? ? celler_4.setCellValue("結(jié)算場次明細");
? ? ? ? //創(chuàng)建第三行
? ? ? ? HSSFRow rowsan = sheet.createRow(2);
? ? ? ? //結(jié)算總筆數(shù)
? ? ? ? HSSFCell cellsan_1 = rowsan.createCell(0);
? ? ? ? //借方金額
? ? ? ? HSSFCell cellsan_2 = rowsan.createCell(2);
? ? ? ? //貸方金額
? ? ? ? HSSFCell cellsan_3 = rowsan.createCell(4);
? ? ? ? //結(jié)算場次明細
? ? ? ? HSSFCell cellsan_4 = rowsan.createCell(6);
? ? ? ? //加載單元格樣式
? ? ? ? cellsan_1.setCellStyle(cell_Style);
? ? ? ? cellsan_1.setCellValue(accountInfoEntityResp.getSttlCntNb());
? ? ? ? cellsan_2.setCellStyle(cell_Style);
? ? ? ? String tmpVal = String.valueOf(accountInfoEntityResp.getDebitCntAmt());
? ? ? ? cellsan_2.setCellValue(tmpVal);
? ? ? ? cellsan_3.setCellStyle(cell_Style);
? ? ? ? String tmpVal2 = String.valueOf(accountInfoEntityResp.getCreditCntAmt());
? ? ? ? cellsan_3.setCellValue(tmpVal2);
? ? ? ? cellsan_4.setCellStyle(cell_Style);
? ? ? ? cellsan_4.setCellValue("");
? ? ? ? //創(chuàng)建明細標題、結(jié)算場次列表標題、批次列表標題唧席、分項列表標題
? ? ? ? //第四行:明細
? ? ? ? HSSFRow rowsi = sheet.createRow(3);
? ? ? ? HSSFCell cellsi = rowsi.createCell(0);
? ? ? ? //加載單元格樣式
? ? ? ? cellsi.setCellStyle(cell_Style);
? ? ? ? cellsi.setCellValue("明細");
? ? ? ? //第五行:結(jié)算場次列表
? ? ? ? HSSFRow rowwu = sheet.createRow(4);
? ? ? ? HSSFCell cellwu = rowwu.createCell(0);
? ? ? ? //加載單元格樣式
? ? ? ? cellwu.setCellStyle(cell_Style);
? ? ? ? cellwu.setCellValue("結(jié)算場次列表");
? ? ? ? //第六行:結(jié)算場次列表-標題欄
? ? ? ? HSSFRow rowsix = sheet.createRow(5);
? ? ? ? HSSFCell cellsix_1 = rowsix.createCell(0);
? ? ? ? HSSFCell cellsix_2 = rowsix.createCell(1);
? ? ? ? HSSFCell cellsix_3 = rowsix.createCell(2);
? ? ? ? //加載單元格樣式
? ? ? ? cellsix_1.setCellStyle(cell_Style);
? ? ? ? cellsix_1.setCellValue("報文標識號");
? ? ? ? cellsix_2.setCellStyle(cell_Style);
? ? ? ? cellsix_2.setCellValue("場次借貸標識");
? ? ? ? cellsix_3.setCellStyle(cell_Style);
? ? ? ? cellsix_3.setCellValue("場次金額");
? ? ? ? //第7行:批次列表
? ? ? ? HSSFRow rowseven = sheet.createRow(sttlInfCount+4+1);
? ? ? ? HSSFCell cellseven = rowseven.createCell(0);
? ? ? ? //加載單元格樣式
? ? ? ? cellseven.setCellStyle(cell_Style);
? ? ? ? cellseven.setCellValue("批次列表");
? ? ? ? //第8行:批次列表-->標題欄
? ? ? ? HSSFRow rowsegiht = sheet.createRow(sttlInfCount+4+2);
? ? ? ? HSSFCell cellegiht_1 = rowsegiht.createCell(0);
? ? ? ? HSSFCell cellegiht_2 = rowsegiht.createCell(1);
? ? ? ? HSSFCell cellegiht_3 = rowsegiht.createCell(2);
? ? ? ? HSSFCell cellegiht_4 = rowsegiht.createCell(3);
? ? ? ? //加載單元格樣式
? ? ? ? cellegiht_1.setCellStyle(cell_Style);
? ? ? ? cellegiht_1.setCellValue("報文標識號");
? ? ? ? cellegiht_2.setCellStyle(cell_Style);
? ? ? ? cellegiht_2.setCellValue("批次號");
? ? ? ? cellegiht_3.setCellStyle(cell_Style);
? ? ? ? cellegiht_3.setCellValue("批次借貸標識");
? ? ? ? cellegiht_4.setCellStyle(cell_Style);
? ? ? ? cellegiht_4.setCellValue("批次金額");
? ? ? ? //第9行:分項列表
? ? ? ? HSSFRow rowba = sheet.createRow(sttlInfCount+4+1+batchInfCount+1);
? ? ? ? HSSFCell cellba = rowba.createCell(0);
? ? ? ? //加載單元格樣式
? ? ? ? cellba.setCellStyle(cell_Style);
? ? ? ? cellba.setCellValue("分項列表");
? ? ? ? //第10行:分項列表—>標題欄
? ? ? ? HSSFRow rowsten = sheet.createRow(sttlInfCount+4+1+batchInfCount+2);
? ? ? ? HSSFCell cellten_1 = rowsten.createCell(0);
? ? ? ? HSSFCell cellten_2 = rowsten.createCell(1);
? ? ? ? HSSFCell cellten_3 = rowsten.createCell(2);
? ? ? ? HSSFCell cellten_4 = rowsten.createCell(3);
? ? ? ? HSSFCell cellten_5 = rowsten.createCell(4);
? ? ? ? HSSFCell cellten_6 = rowsten.createCell(5);
? ? ? ? HSSFCell cellten_7 = rowsten.createCell(6);
? ? ? ? HSSFCell cellten_8 = rowsten.createCell(7);
? ? ? ? //加載單元格樣式
? ? ? ? cellten_1.setCellStyle(cell_Style);
? ? ? ? cellten_1.setCellValue("批次號");
? ? ? ? cellten_2.setCellStyle(cell_Style);
? ? ? ? cellten_2.setCellValue("業(yè)務(wù)類型");
? ? ? ? cellten_3.setCellStyle(cell_Style);
? ? ? ? cellten_3.setCellValue("銀行金額機構(gòu)標識");
? ? ? ? cellten_4.setCellStyle(cell_Style);
? ? ? ? cellten_4.setCellValue("賬戶類型");
? ? ? ? cellten_5.setCellStyle(cell_Style);
? ? ? ? cellten_5.setCellValue("分項借方發(fā)生額");
? ? ? ? cellten_6.setCellStyle(cell_Style);
? ? ? ? cellten_6.setCellValue("分項借方發(fā)生筆數(shù)");
? ? ? ? cellten_7.setCellStyle(cell_Style);
? ? ? ? cellten_7.setCellValue("分項貸方發(fā)生額");
? ? ? ? cellten_8.setCellStyle(cell_Style);
? ? ? ? cellten_8.setCellValue("分項貸方發(fā)生筆數(shù)");
? ? ? ? //結(jié)算場次列表、批次列表數(shù)據(jù)鳄袍、分項列表數(shù)據(jù)
? ? ? ? List<SttlInf> sttlList = new ArrayList<SttlInf>();
? ? ? ? if(accountInfoEntityResp.getSttlList() != null ){
? ? ? ? ? ? sttlList = accountInfoEntityResp.getSttlList();
? ? ? ? }
? ? ? ? //5.操作單元格;將列表數(shù)據(jù)寫入excel
? ? ? ? if(sttlList != null){
? ? ? ? ? ? //結(jié)算場次列表數(shù)據(jù)
? ? ? ? ? ? //批次列表循環(huán)計數(shù)器
? ? ? ? ? ? int batInfCount = 0;
? ? ? ? ? ? //分項列表循環(huán)計數(shù)器
? ? ? ? ? ? int subItInfCount = 0;
? ? ? ? ? ? for(int j=0; j< sttlList.size(); j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? HSSFRow row3 = sheet.createRow(j+6);
? ? ? ? ? ? ? ? HSSFCell cell0 = row3.createCell(0);
? ? ? ? ? ? ? ? cell0.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? cell0.setCellValue(sttlList.get(j).getSttlReptFlg());
? ? ? ? ? ? ? ? HSSFCell cell1 = row3.createCell(1);
? ? ? ? ? ? ? ? cell1.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? cell1.setCellValue(DCFlag(sttlList.get(j).getSttlDCFlg()));
? ? ? ? ? ? ? ? HSSFCell cell2 = row3.createCell(2);
? ? ? ? ? ? ? ? cell2.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? cell2.setCellValue(String.valueOf(sttlList.get(j).getSttlAmt()));
? ? ? ? ? ? ? ? List<BatchInf> BatchList = new ArrayList<BatchInf>();
? ? ? ? ? ? ? ? if(sttlList.get(j).getBatchList() != null){
? ? ? ? ? ? ? ? ? ? BatchList = sttlList.get(j).getBatchList();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if(BatchList != null){
? ? ? ? ? ? ? ? ? ? //批次列表數(shù)據(jù)
? ? ? ? ? ? ? ? ? ? for(int i = 0; i< BatchList.size(); i++){
? ? ? ? ? ? ? ? ? ? ? ? batInfCount++;
? ? ? ? ? ? ? ? ? ? ? ? HSSFRow row4 = sheet.createRow(sttlList.size()+6+1+batInfCount);
? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell3 = row4.createCell(0);
? ? ? ? ? ? ? ? ? ? ? ? cell3.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? cell3.setCellValue(sttlList.get(j).getSttlReptFlg());
? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell4 = row4.createCell(1);
? ? ? ? ? ? ? ? ? ? ? ? cell4.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? cell4.setCellValue(BatchList.get(i).getBatchId());
? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell5 = row4.createCell(2);
? ? ? ? ? ? ? ? ? ? ? ? cell5.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? cell5.setCellValue(DCFlag(BatchList.get(i).getBatchDCFlg()));
? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell6 = row4.createCell(3);
? ? ? ? ? ? ? ? ? ? ? ? cell6.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? cell6.setCellValue(String.valueOf(BatchList.get(i).getBatchNetAmt()));
? ? ? ? ? ? ? ? ? ? ? ? List<SubItemInf> SubItemList = new ArrayList<SubItemInf>();
? ? ? ? ? ? ? ? ? ? ? ? if(BatchList.get(i).getSubItemList() != null){
? ? ? ? ? ? ? ? ? ? ? ? ? ? SubItemList = BatchList.get(i).getSubItemList();
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? //分項列表數(shù)據(jù)
? ? ? ? ? ? ? ? ? ? ? ? if(SubItemList != null) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? for (int f = 0; f < SubItemList.size(); f++) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? subItInfCount++;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? HSSFRow row5 = sheet.createRow((sttlInfCount+4+1+batchInfCount+2)+subItInfCount);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell7 = row5.createCell(0);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell7.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell7.setCellValue(BatchList.get(i).getBatchId());
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? String SubItemInf = SubItemList.get(f).getSubItemInf().replace("CNY","");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? String[] subArray = {};
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? subArray = SubItemInf.split("\\|");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell8 = row5.createCell(1);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell8.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell8.setCellValue(busiType(subArray[0]));
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell9 = row5.createCell(2);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell9.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell9.setCellValue(subArray[1]);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell10 = row5.createCell(3);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell10.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell10.setCellValue(accountType(subArray[2]));
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell11 = row5.createCell(4);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell11.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell11.setCellValue(subArray[3]);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell12 = row5.createCell(5);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell12.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell12.setCellValue(subArray[4]);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell13 = row5.createCell(6);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell13.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell13.setCellValue(subArray[5]);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? HSSFCell cell14 = row5.createCell(7);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell14.setCellStyle(cell_Style);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cell14.setCellValue(subArray[6]);
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? String downFilename = "accountInfo.xls";
? ? ? ? // 獲取文件的MIME類型:
? ? ? ServletContext servletContext = request.getServletContext();
? ? ? ? String contentType = servletContext.getMimeType(downFilename);
? ? ? ? // 將MIME類型放入響應(yīng)
? ? ? ? response.setContentType(contentType);
? ? ? ? // 瀏覽器類型
? ? ? ? String agent = request.getHeader("user-agent");
? ? ? ? // 獲取附件的名字和下載方式
? ? ? ? String contentDisposition = "attachment;filename=" + downFilename;
? ? ? ? // 將附件名字和下載方式放入響應(yīng)頭信息中
? ? ? ? response.setHeader("Content-Disposition", contentDisposition);
? ? ? ? // 告訴瀏覽器用什么軟件可以打開此文件
? ? ? ? /*response.setHeader("content-Type", "application/vnd.ms-excel");
? ? ? ? // 下載文件的默認名稱
? ? ? ? response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(downFilename, "utf-8"));*/
? ? ? ? ServletOutputStream out = response.getOutputStream();
? ? ? ? wb.write(out);
? ? ? ? out.close();
? ? }
最終導(dǎo)出excel表格如下:
關(guān)注個人技術(shù)公眾號:nick_coding1024
不定期分享最新前沿技術(shù)框架和bat大廠常用技術(shù)等,加群不定期分享行業(yè)內(nèi)大牛直播講課以及獲得內(nèi)退一線互聯(lián)網(wǎng)公司機會吏恭。
---------------------CSDN技術(shù)博客
原文:https://blog.csdn.net/xuri24/article/details/83112954