ExcelUtils 導表執行個體

來源:互聯網
上載者:User

標籤:http   os   for   io   htm   new   

@RequestMapping("/dealer/chargebook/exportv.htm")
    public void getChargeBookList(int epmkey,String bdakey,int year,int month,HttpServletRequest request, HttpServletResponse response) {
        List<ChargeBook> list = chargeBookService.getEpmChargeBookList(epmkey,year,month,bdakey);
            String filename = year+"年"+month+"月份"+list.get(0).getCbkBdaCaption()+"物業繳費統計.xls";
            filename = encodeFilename(filename, request);//設定下載時用戶端Excel的名稱
            response.setHeader("Content-disposition", "attachment;filename="+filename);
            response.setContentType("application/vnd.ms-excel");
            String config = "/WEB-INF/chargebook/balance.xls";
            ExcelUtils.addValue("month", month);
            ExcelUtils.addValue("year", year);
            ExcelUtils.addValue("bdaCaption", list.get(0).getCbkBdaCaption());
            for (ChargeBook chargeBook : list) {
                chargeBook.setCbkRemark(rdStatus(chargeBook.getCbkStatus()));
            }
            ExcelUtils.addValue("list", list);
            ExcelUtils.addValue("service",rdStatus(0) );
            try {
                ExcelUtils.export(request.getSession().getServletContext(),config,response.getOutputStream());
            } catch (ExcelException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    
     public static String encodeFilename(String filename, HttpServletRequest request) {    
            /**  
             * 擷取用戶端瀏覽器和作業系統資訊  
             * 在IE瀏覽器中得到的是:User-Agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; Alexa Toolbar)  
             * 在Firefox中得到的是:User-Agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.7.10) Gecko/20050717 Firefox/1.0.6  
             */    
            String agent = request.getHeader("USER-AGENT");    
            try {    
              if ((agent != null) && (-1 != agent.indexOf("MSIE"))) {    
                String newFileName = URLEncoder.encode(filename, "UTF-8");    
                newFileName = StringUtils.replace(newFileName, "+", "%20");    
                if (newFileName.length() > 150) {    
                  newFileName = new String(filename.getBytes("GB2312"), "ISO8859-1");    
                  newFileName = StringUtils.replace(newFileName, " ", "%20");    
                }    
                return newFileName;    
              }    
              if ((agent != null) && (-1 != agent.indexOf("Mozilla")))    
                return MimeUtility.encodeText(filename, "UTF-8", "B");    
            
              return filename;    
            } catch (Exception ex) {    
              return filename;    
            }    
         }

 

Excel 取值 : #foreach cb in ${list}  #end

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.