下载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'">导出有效订单</button>

2.后台代码处理:

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 = { "订单日期", "订单号", "商品名称", "商品属性", "渠道名称", "支付银行卡","支付账号", "成本价", "卖出价", "卖出收入", "发货日期", "外订单审核日期", "退货日期", "取消日期" };

  List<FenqiGoodsOrder> returnOrders = fenqiGoodsOrderListService

    .exportReturnThirdList(startTime, endTime);

  String path = "";

OrderDetailExportExeclUtil.exeportListData(heads, returnOrders,response);

 }

导出到execl处理逻辑:

public static void  exeportListData(String[] heads,List<FenqiGoodsOrder> returnOrders,HttpServletResponse response){

  // 第一步。创建一个webbook,相应一个Excel文件  

        HSSFWorkbook wb = new HSSFWorkbook(); 

       // 第二步。在webbook中加入一个sheet,相应Excel文件里的sheet  

        HSSFSheet sheet = wb.createSheet("第三方退货订单明细"); 

       // 第三步,在sheet中加入表头第0行,注意老版本号poi对Excel的行数列数有限制short  

        HSSFRow row = sheet.createRow((int) 0); 

     // 第四步。创建单元格,并设置值表头 设置表头居中  

     HSSFCellStyle style = wb.createCellStyle(); 

     style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

HSSFCell cell=null;

         for(int h=0;h<heads.length;h++){

          cell = row.createCell((short) h); 

          cell.setCellValue(heads[h]); 

       cell.setCellStyle(style); 

         }

     // 第五步,写入实体数据 实际应用中这些数据从数据库得到,  

        for (int i = 0; i < returnOrders.size(); i++) 

       { 

            row = sheet.createRow((int) i + 1); 

            FenqiGoodsOrder goodsOrder = (FenqiGoodsOrder) returnOrders.get(i); 

           // 第四步,创建单元格,并设置值  

            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());//成本价

            row.createCell((short) 8).setCellValue(goodsOrder.getSellPrice());//卖出价

            row.createCell((short) 9).setCellValue(goodsOrder.getSellEarning());//卖出收入 

            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

下载并导出数据到execl中的更多相关文章

  1. 手把手教你springboot中导出数据到excel中

    手把手教你springboot中导出数据到excel中 问题来源: 前一段时间公司的项目有个导出数据的需求,要求能够实现全部导出也可以多选批量导出(虽然不是我负责的,我自己研究了研究),我们的项目是x ...

  2. MySQL导出数据到文件中的方法

    MySQL导出数据到文件中的方法 1.导出数据到txt文件中实例:把数据表studscoreinfo中所有数据导出到指定的位置方法:select * from 表名 into outfile 指定导出 ...

  3. 1.ASP.NET MVC使用EPPlus,导出数据到Excel中

    好久没写博客了,今天特地来更新一下,今天我们要学习的是如何导出数据到Excel文件中,这里我使用的是免费开源的Epplus组件. 源代码下载:https://github.com/caofangshe ...

  4. 【转】c# winform DataGridView导出数据到Excel中,可以导出当前页和全部数据

    准备工作就是可以分页的DataGridView,和两个按钮,一个用来导出当前页数据到Excel,一个用来导出全部数据到Excel 没有使用SaveFileDialog,但却可以弹出保存对话框来 先做导 ...

  5. 利用NPOI导出数据到Execl

    相信很多童鞋都开发过Execl的导入导出功能,最近产品中无论是后台数据分析的需要,还是前端满足用户管理的方便,都有Execl导入导出的维护需求产生. 以前做这个功能,如果是web,利用HttpCont ...

  6. python 导出数据到excel 中,一个好用的导出数据到excel模块,XlsxWriter

    最近公司有项目需要导出数据到excel,首先想到了,tablib,xlwt,xlrd,xlwings,win32com[还可以操作word],openpyxl,等模块但是 实际操作中tablib 写入 ...

  7. 关于2020.04.26【MySQL导出数据到文件中的方法】的补充

    之前导出的数据文件中没有表的列名,感觉不够完整,摸索一下发现带表列名导出也是可以的,只试了导出txt和csv两种文件类型的方法.       1.导出数据到txt文件中(包含数据表列名)的方法:先选择 ...

  8. C#自定义导出数据到Excel中的类封装

    using System; using System.IO; using System.Data; using System.Collections; using System.Data.OleDb; ...

  9. MySQL导出数据到文件中

    一.导出一张表数据 把test_time表中的数据导出成txt 文件 mysql> show global variables like '%secure%'; +--------------- ...

随机推荐

  1. c# await 到底等待的是什么?

    static void Main(string[] args) { Print(); Console.WriteLine("5 :::" + Thread.CurrentThrea ...

  2. POJ 3735 Training little cats(矩阵乘法)

    [题目链接] http://poj.org/problem?id=3735 [题目大意] 有一排小猫,给出一系列操作,包括给一只猫一颗花生, 让某只猫吃完所有的花生以及交换两只猫的花生, 求完成m次操 ...

  3. OpenFire匿名登陆

    原文:http://blog.csdn.net/majian_1987/article/details/9714529 首先在服务的控制台,设置允许匿名登陆,设置界面如下: package com.b ...

  4. LinuxPAServer19.0.tar.gz压缩包

    LinuxPAServer19.0.tar.gz DELPHI XE10.2(TOKYO)开始可以编写LINUX控制台程序.在LINUX上面需要部署LinuxPAServer19.0.tar.gz,即 ...

  5. xcode 6 exporting ipa 提示 Your account already has a valid iOS distribution certificate

    在Product - Archive 包过程中,选择Save for Ad hoc Deployment模式[给内部人员测试],export包时,弹出了如下提示 自己遇到时候问题:首先adhoc需要本 ...

  6. AJAX enabled & disabled

    @model string           @{    ViewBag.Title = "GetPeople";    AjaxOptions ajaxOpts = new A ...

  7. #define,#undef宏学习

    1.预处理器 1.1预处理符号: __FILE__ :进行编译的源文件名字 __LINE__ :文件当前行的行号 __DATA__ :文件被编译的日期 __TIME__ :文件被编译的时间 __STD ...

  8. 查看Linux服务器CPU使用率、内存使用率、磁盘空间占用率、负载情况

    [root@server script]# vi monitor.py #!/usr/bin/env python # -*- coding:utf-8 -*- #Author: nulige imp ...

  9. SVM相关知识及和softmax区别

    1.相对于容易过度拟合训练样本的人工神经网络,支持向量机对于未见过的测试样本具有更好的推广能力. 2.SVM更偏好解释数据的简单模型---二维空间中的直线,三维空间中的平面和更高维空间中的超平面. 3 ...

  10. Python 面向对象二(转载)

    来源:www.cnblogs.com/wupeiqi/p/4766801.html 三.类成员的修饰符 类的所有成员在上一步骤中已经做了详细的介绍,对于每一个类的成员而言都有两种形式: 1.公有成员, ...