日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

下载并导出数据到execl中

發(fā)布時(shí)間:2025/7/14 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 下载并导出数据到execl中 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

下載poi-3.6-20091214.jar。下載地址例如以下:

http://download.csdn.net/detail/evangel_z/3895051

1.jsp

<button type="button" class="btn btn-mini" onClick="location.href='<%=basePath%>/bankcard/exportEffectThirdData?

begintime=${begintime}&endtime=${endtime}&page=1'">導(dǎo)出有效訂單</button>

2.后臺(tái)代碼處理:

?controller 處理:

@Get("exportReturnThirdData")
?public? void? exportReturnThirdListData(Invocation inv,@Param("begintime") String startTime,
???@Param("endtime") String endTime){
??HttpServletResponse response = inv.getResponse();
??// response.setContentType("application/xls");
??response.setContentType("application/x-download");
??response.reset();
??response.setContentType("bin");
??String header = "attachment;filename=returnThirdData.xls";
??response.addHeader("Content-Disposition", header);

??String[] heads = { "訂單日期", "訂單號(hào)", "商品名稱", "商品屬性", "渠道名稱", "支付銀行卡","支付賬號(hào)", "成本價(jià)", "賣(mài)出價(jià)", "賣(mài)出收入", "發(fā)貨日期", "外訂單審核日期", "退貨日期", "取消日期" };
??List<FenqiGoodsOrder> returnOrders = fenqiGoodsOrderListService
????.exportReturnThirdList(startTime, endTime);
??String path = "";

??OrderDetailExportExeclUtil.exeportListData(heads, returnOrders,response);
?}

導(dǎo)出到execl處理邏輯:

public static void? exeportListData(String[] heads,List<FenqiGoodsOrder> returnOrders,HttpServletResponse response){
??// 第一步。創(chuàng)建一個(gè)webbook,相應(yīng)一個(gè)Excel文件??
??????? HSSFWorkbook wb = new HSSFWorkbook();?
?????? // 第二步。在webbook中加入一個(gè)sheet,相應(yīng)Excel文件里的sheet??
??????? HSSFSheet sheet = wb.createSheet("第三方退貨訂單明細(xì)");?
?????? // 第三步,在sheet中加入表頭第0行,注意老版本號(hào)poi對(duì)Excel的行數(shù)列數(shù)有限制short??
??????? HSSFRow row = sheet.createRow((int) 0);?
???? // 第四步。創(chuàng)建單元格,并設(shè)置值表頭 設(shè)置表頭居中??
???? HSSFCellStyle style = wb.createCellStyle();?
???? style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 創(chuàng)建一個(gè)居中格式??

???? HSSFCell cell=null;
???????? for(int h=0;h<heads.length;h++){
??????? ? cell = row.createCell((short) h);?
??????? ? cell.setCellValue(heads[h]);?
?????? cell.setCellStyle(style);?
???????? }
???? // 第五步,寫(xiě)入實(shí)體數(shù)據(jù) 實(shí)際應(yīng)用中這些數(shù)據(jù)從數(shù)據(jù)庫(kù)得到,??
??????? for (int i = 0; i < returnOrders.size(); i++)?
?????? {?
??????????? row = sheet.createRow((int) i + 1);?
??????????? FenqiGoodsOrder goodsOrder = (FenqiGoodsOrder) returnOrders.get(i);?
?????????? // 第四步,創(chuàng)建單元格,并設(shè)置值??
??????????? row.createCell((short) 0).setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(goodsOrder.getCreateTime()));?
??????????? row.createCell((short) 1).setCellValue(goodsOrder.getOrderNo());?
??????????? row.createCell((short) 2).setCellValue(goodsOrder.getGoodName());?
??????????? row.createCell((short) 3).setCellValue(goodsOrder.getGoodType());
??????????? row.createCell((short) 4).setCellValue(goodsOrder.getChannelName());?
??????????? row.createCell((short) 5).setCellValue(goodsOrder.getCardNo());?
??????????? row.createCell((short) 6).setCellValue(goodsOrder.getAccountNo());?
??????????? row.createCell((short) 7).setCellValue(goodsOrder.getPurchasePrice());//成本價(jià)
??????????? row.createCell((short) 8).setCellValue(goodsOrder.getSellPrice());//賣(mài)出價(jià)
??????????? row.createCell((short) 9).setCellValue(goodsOrder.getSellEarning());//賣(mài)出收入?
??????????? if(goodsOrder.getDeliveryTime() !=null && !goodsOrder.getDeliveryTime().equals("")){
???????? ??? row.createCell((short) 10).setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(goodsOrder.getDeliveryTime()));?
??????????? }
??????????? if(goodsOrder.getAuditTime() !=null && !goodsOrder.getAuditTime().equals("")){
???????? ??? row.createCell((short) 11).setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(goodsOrder.getAuditTime()));
??????????? }
??????????? if(goodsOrder.getReturnTime() !=null && !goodsOrder.getReturnTime().equals("")){
???????? ??? row.createCell((short) 12).setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(goodsOrder.getReturnTime()));?
??????????? }
??????????? if(goodsOrder.getCancelDate() !=null && !goodsOrder.getCancelDate().equals("")){
???????? ??? row.createCell((short) 13).setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(goodsOrder.getCancelDate()));
??????????? }
???????? }?
???????? // 第六步,將文件存到指定位置??
??????? try?
??????? {?
???????? wb.write(response.getOutputStream());?
??????? }?
?????? catch (Exception e)?
?????? {?
??????????? e.printStackTrace();?
??????? }?
??
?}

?

?

?http://www.cnblogs.com/bmbm/archive/2011/12/08/2342261.html

總結(jié)

以上是生活随笔為你收集整理的下载并导出数据到execl中的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。