aspose-cells导出excel

 // 备注:代码只能做aspose-cells写法参照,不能直接运行
 public static String exportExcel(HttpServletRequest request, HttpServletResponse response) {
            String reportPath   = UtilProperties.getPropertyValue("customize.properties", "customize.template.path");
            
            String wxhPaymentXlsPath = reportPath+"/"+"wxh-payment.xls";
            
            String fileNameNew = "wxh-payment"+MyDateUtil.getDateCodeByCurrent()+".xls";
            String wxhPaymentXlsPathSave = reportPath+"/"+fileNameNew;
            
            if(wxhPaymentXlsPath.indexOf("xls") >0){
                
                response.setContentType("application/x-download");
                response.setHeader("Content-Disposition", "attachment; filename=\"" + fileNameNew+"\"");
                
                Workbook wb = new Workbook(wxhPaymentXlsPath);
                WorkbookDesigner designer = new WorkbookDesigner();
                
                // 设置公共变量值
                designer.setDataSource("date",MyDateUtil.getCurrentDateByYMDHMS());
                designer.setDataSource("account",MySystemUtil.getUserLoginId(request));
                
                // 创建每一行数据
                List<ReportObjectWxhPayment> listReport = new ArrayList<ReportObjectWxhPayment>();
                for(int i=0;i<gridlist.size();i++){
                    Map mapOrder = (Map)gridlist.get(i);
                    ReportObjectWxhPayment report = new ReportObjectWxhPayment();
                    report.setCost(""+mapOrder.get("Meta_cost"));
                    report.setCouponNameBrand(""+mapOrder.get("META_CPNS_NAME_BRAND"));
                    
                    String couponMoneyBrand = getCouponMontyTotal(request,""+mapOrder.get("META_CPNS_ID_BRAND"));
                    report.setCouponMoneyBrand(""+couponMoneyBrand);
                    report.setCommission(""+mapOrder.get("Meta_commission"));
                    report.setVendorPayTime(""+mapOrder.get("Meta_supplierpaytime"));
                    report.setPayTimeWxh(""+mapOrder.get("Meta_wxhkrpayime"));
                    report.setPaymentNo(""+mapOrder.get("Meta_venderpayno"));
                    report.setCompanyTitle(""+mapOrder.get("Meta_storeinvocename"));  
                    listReport.add(report);
                }
                
                designer.setDataSource("object",listReport);
                designer.setWorkbook(wb);
                designer.process();
                wb.save(wxhPaymentXlsPathSave);
                
                 OutputStream os = response.getOutputStream();
                 FileInputStream fis = new FileInputStream(wxhPaymentXlsPathSave);
                 int c;
                 while ((c = fis.read()) != -1) {
                     os.write(c);
                 }
                 os.flush();
                 fis.close();
            }
            
            // Delete file
            MyFileUtil.deleteFile(wxhPaymentXlsPathSave);
         
         return "";
}



你可能感兴趣的:(aspose-cells导出excel)