码迷,mamicode.com
首页 > 其他好文 > 详细

jeecg导出备份

时间:2019-12-25 14:34:27      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:ted   日期   select   typename   开始   simple   path   div   方式   

导出前台

<t:dgToolBar title="导出" icon="fa fa-upload" funname="ExportXldiaodu"></t:dgToolBar>

 

一、
function ExportXldiaodu(title,url,gname) { gridname
=gname; var ids = []; var rows = $("#"+gname).datagrid(‘getSelections‘); for ( var i = 0; i < rows.length; i++) { ids.push(rows[i].id); } var ordercode=$("input[name=‘crOrderno1‘]").val();//业务编号 var crOrderstate=$("select[name=‘crOrderstate‘]").val();//运输状态 var crNo=$("input[name=‘crNo‘]").val();//车队编号 var crEtdGettime_begin=$("input[name=‘crEtdGettime_begin‘]").val();//车队编号 var crEtdGettime_end=$("input[name=‘crEtdGettime_end‘]").val();//车队编号 var ordertype=$(‘#crPcname1‘).val();//业务类型 var crInno=$("input[name=‘crInno‘]").val();//进仓编号 var orderman=$(‘#crOrderFromcompany‘).val();//委托单位 var crBoxbillno = $("input[name=‘crBoxbillno‘]").val();//提单号 var ordertype2=$(‘#crPcname2‘).val();//业务类型安顺 var busname =$("select[name=‘busname‘]").val();//业务性质 var createDatebegin = $("input[name=‘createDate_begin‘]").val();//下单开始时间 var createDateend = $("input[name=‘createDate_end‘]").val();//下单结束时间 var crFromDispatcher = $("select[name=‘crFromDispatcher‘]").val();//接单人 var createBy = $("select[name=‘createBy‘]").val();//下单人 var updateName = $("select[name=‘updateName‘]").val();//更新人 var crGettime_begin = $("input[name=‘crGettime_begin‘]").val(); //实际提货时间开始 var crGettime_end = $("input[name=‘crGettime_end‘]").val();//实际提货时间结束 var crTxweituono = $("input[name=‘crTxweituono‘]").val();//提货单号 var crSumitstate = $("input[name=‘crSumitstate‘]").val();//提箱委托单号 var crFromCarno = $("input[name=‘crFromCarno‘]").val();//提货车牌 JeecgExcelExport("carRouteController.do?exportXlsthqddiaodu&ids="+ids+"&ordercode="+ordercode+‘&crOrderstate=‘+crOrderstate
          +‘&crNo=‘+crNo+‘&crEtdGettime_begin=‘+crEtdGettime_begin+‘&crEtdGettime_end=‘+crEtdGettime_end+‘&ordertype=‘+ordertype
          +‘&crInno=‘+crInno+‘&orderman=‘+orderman+‘&crBoxbillno=‘+crBoxbillno+‘&ordertype2=‘+ordertype2+‘&busname=‘+busname
          +‘&createDatebegin=‘+createDatebegin+‘&createDateend=‘+createDateend+‘&crFromDispatcher=‘+crFromDispatcher
          +‘&createBy =‘+createBy+‘&updateName=‘+updateName+‘&type=6‘+‘&crGettime_begin=‘+crGettime_begin+‘&crGettime_end=‘+crGettime_end
          +‘&crTxweituono=‘+crTxweituono+‘&crSumitstate=‘+crSumitstate+‘&crFromCarno=‘+crFromCarno , "carRouteList"); }

 

 

二、
function newbaoguan(title,url, id,width,height,isRestful) { gridname
=id; var rowsData = $(‘#‘+id).datagrid(‘getSelections‘); if (!rowsData || rowsData.length==0) { tip(‘请选择导出项目‘); return; } if (rowsData.length>1) { tip(‘请选择一条记录再导出‘); return; } if (rowsData.length==1) { JeecgExcelExport("decMainController.do?newbaoguan&ids="+rowsData[0].id,"decMainList"); } }

 

 

 

 

后台代码

/**
     * 导出 托运单
     */
    @RequestMapping(params = "ExportHjyTyd")
    @ResponseBody
    public void ExportHjyTyd(HttpServletRequest request, ModelMap modelMap, HttpServletResponse response,
            OutputStream output) throws UnsupportedEncodingException {
        Workbook tempWorkBook = null;
        String id = request.getParameter("id");//业务编号
        String ids = request.getParameter("ids");//选择框
        String wheresql = " ";

        if(id!=null && !id.equals("")) {
            wheresql += " and a.id=‘" + id + "‘";
        }
        
        if(ids !=null && !ids.equals("")) {
            wheresql += " and b.id=‘" + ids + "‘";
        }
        
        String sql = " select a.* ,b.*,sysdate() sysdate  " 
                   + "   from ldc_order a,car_route b"
                   + "  where a.order_code = b.cr_orderno  "
                   + wheresql 
                   + "  order by b.create_date desc ";

        String lujing = request.getSession().getServletContext().getRealPath("/");
        String lujing1 = lujing + "export\\template\\exporthjytyd.xlsx";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
        InputStream in;
        try {
            in = new FileInputStream(new File(lujing1));
            XSSFWorkbook work = null;
            work = new XSSFWorkbook(in);
            this.ExportHjyTydOut(request, response, work, maps);
        } catch (Exception e) {

            e.printStackTrace();
        }


    }
    /**
     * 导出托运单动作
     */
    public void ExportHjyTydOut(HttpServletRequest request, HttpServletResponse response, XSSFWorkbook work, List<Map<String, Object>> list) {
        
        
        XSSFSheet sheetAt = work.getSheetAt(0);     
        XSSFRow row1 = sheetAt.getRow(1);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString ="";
         
         Map<String, Object> map = new HashMap<>();
         map = list.get(0);
         
       /*
        * 从第三行开始赋值 
        */
         XSSFRow row3 =  sheetAt.getRow(2);
        //发货日期
         if(map.get("create_date") !=null) {
             Date date = (Date) map.get("create_date");
             dateString = formatter.format(date);
             row3.getCell(2).setCellValue(dateString);
         }else {
             row3.getCell(2).setCellValue("");         
         }
         
        //导出日期
         String qq = formatter.format(map.get("sysdate"));
        row3.getCell(7).setCellValue(formatter.format(map.get("sysdate")));    
        
        //业务编号
         if(map.get("order_code") !=null) {
             row3.getCell(12).setCellValue(String.valueOf(map.get("order_code")));
         }else {
             row3.getCell(12).setCellValue("");         
         }
         
        /*
         *    从第四行开始赋值 
         */
         XSSFRow row4 = sheetAt.getRow(3);
         //提货联系人
         if(map.get("cr_Fromperson") !=null) {
             row4.getCell(2).setCellValue(String.valueOf(map.get("cr_Fromperson")));
         }else {
             row4.getCell(2).setCellValue("");         
         }
         //提货联系人电话
         if(map.get("cr_Frompersontel") !=null) {
             row4.getCell(5).setCellValue(String.valueOf(map.get("cr_Frompersontel")));
         }else {
             row4.getCell(5).setCellValue("");         
         }
         //提货地址
         if(map.get("cr_Fromplace_Value") !=null) {
             row4.getCell(8).setCellValue(String.valueOf(map.get("cr_Fromplace_Value")));
         }else {
             row4.getCell(8).setCellValue("");         
         }
         
         /*
         *    从第5行开始赋值 
         */
         XSSFRow row5 = sheetAt.getRow(4);
         //送货联系人
         if(map.get("cr_Toperson") !=null) {
             row5.getCell(2).setCellValue(String.valueOf(map.get("cr_Toperson")));
         }else {
             row5.getCell(2).setCellValue("");         
         }
         //送货联系人电话
         if(map.get("cr_Topersontel") !=null) {
             row5.getCell(5).setCellValue(String.valueOf(map.get("cr_Topersontel")));
         }else {
             row5.getCell(5).setCellValue("");         
         }
         //送货地址
         if(map.get("cr_Toplace_Value") !=null) {
             row5.getCell(8).setCellValue(String.valueOf(map.get("cr_Toplace_Value")));
         }else {
             row5.getCell(8).setCellValue("");         
         }
         
         /*
          *    从第6行开始赋值 orderFk
          */
         XSSFRow row6 = sheetAt.getRow(5);
         //付款方式
         if(map.get("cr_Proteacty") !=null) {
             row6.getCell(10).setCellValue(String.valueOf(map.get("cr_Proteacty")));
         }else {
             row6.getCell(10).setCellValue("");         
         }
        //交货方式
         if(map.get("order_Licenceno") !=null) {
             row6.getCell(13).setCellValue(String.valueOf(map.get("order_Licenceno")));
         }else {
             row6.getCell(13).setCellValue("");         
         }
         
         /*
         *    从第7行开始赋值 
         */
         XSSFRow row7 = sheetAt.getRow(6);
         //货物
         if(map.get("order_Goods") !=null) {
             row7.getCell(1).setCellValue(String.valueOf(map.get("order_Goods")));
         }else {
             row7.getCell(1).setCellValue("");         
         }
         //件数
         if(map.get("order_Number") !=null) {
             row7.getCell(2).setCellValue(String.valueOf(map.get("order_Number")));
         }else {
             row7.getCell(2).setCellValue("");         
         }
         //包装
         if(map.get("order_Bz") !=null && !"".equals(map.get("order_Bz"))) {
             String sql = " select  typename  from t_s_type " 
                         + "  where typegroupid=(select id from t_s_typegroup where typegroupcode=‘orderbz‘)"
                         + "    and typecode  = ‘"+(String)map.get("order_Bz")+"‘";
             
             row7.getCell(3).setCellValue(String.valueOf(map.get("order_Bz")));
         }else {
             row7.getCell(3).setCellValue("");                 
         }
         //重量(KG)
         if(map.get("order_Gross_Weight") !=null) {
             row7.getCell(4).setCellValue(String.valueOf(map.get("order_Gross_Weight")));
         }else {
             row7.getCell(4).setCellValue("");         
         }
         //尺寸
         if(map.get("order_Size") !=null) {
             row7.getCell(5).setCellValue(String.valueOf(map.get("order_Size")));
         }else {
             row7.getCell(5).setCellValue("");         
         }
         
         /*
          *    从第9行开始赋值 
          */
         XSSFRow row9 = sheetAt.getRow(8);
         //备注
         if(map.get("cr_From_Comment") !=null) {
             row9.getCell(12).setCellValue(String.valueOf(map.get("cr_From_Comment")));
         }else {
             row9.getCell(12).setCellValue("");         
         }
        
        //前台反应
        response.reset();  
        response.setCharacterEncoding("UTF-8");  
        response.setContentType("application/vnd.ms-excel");  //保证不乱码  
        try
        {
            Date date=new Date();
            SimpleDateFormat format=new SimpleDateFormat("MMddHHmmss");
            String time="bb"+format.format(date)+".xlsx";
            response.setHeader("Content-Disposition","attachment;" + " filename=" + new String(time.getBytes("utf-8"), "ISO-8859-1"));
           
        }
        catch (UnsupportedEncodingException e1) {        
            e1.printStackTrace();
        }  
        try  
        {  
            ByteArrayOutputStream oss =new  ByteArrayOutputStream(); 
            OutputStream os = response.getOutputStream();
            work.write(oss);  
              
            byte temp[] = oss.toByteArray();  
            ByteArrayInputStream in1 = new ByteArrayInputStream(temp);  
            int n = 0;      
            while ((n = in1.read(temp)) >0) {      
                 os.write(temp, 0, n);      
             }    
            os.flush();  
            os.close();  
        } catch(Exception e){
        
            e.printStackTrace();
        }
        
    }

jeecg导出备份

标签:ted   日期   select   typename   开始   simple   path   div   方式   

原文地址:https://www.cnblogs.com/xueblvip/p/12096447.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!