从webRoot中下载Excel

@RequestMapping("downLoad")
    public void downLoad(Offsupervise off1,HttpServletRequest request,HttpServletResponse response,HttpSession session) throws UnsupportedEncodingException{
        
        User user=(User) session.getAttribute(Const.SESSION_USER);
        String excePath1=servletContext.getRealPath("excel");
        System.out.println("---excePath1:"+excePath1);
        String excePath=excePath1.replaceAll("\\\\", "/");
        System.out.println("---excePath:"+excePath);
        String servletPath=request.getSession().getServletContext().getRealPath("/");
        System.out.println("servletPath:"+servletPath);
        System.out.println(excePath+"/030013101154183F20143Z000.xls");
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
    
        
        
        FileOutputStream out;
        Offsupervise off=null;
        if(null!=off1){
            System.out.println(1);
            off=offsuperviseService.getOffsuperviseByOrangId(off1);
            off.setOrgan_id(off1.getOrgan_id());
            off.setYear(off1.getYear());
            off.setQuarter(off1.getQuarter());
        }
        
        
        response.setContentType("APPLICATION/OCTET-STREAM");
        response.setHeader("Content-Disposition", "attachment;filename=Excel.zip");
        response.setHeader("Cache-Control", "max-age=0");
            try {
                ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
                POIFSFileSystem fs1 = new POIFSFileSystem(new FileInputStream(new File(excePath+"/030013101154183F20143Z000.xls")));
                POIFSFileSystem fs2=new POIFSFileSystem(new FileInputStream(new File(excePath+"/030013101154183G20143Z000.xls")));
                POIFSFileSystem fs3=new POIFSFileSystem(new FileInputStream(new File(excePath+"/030013101154183H20143Z000.xls")));
                POIFSFileSystem fs4=new POIFSFileSystem(new FileInputStream(new File(excePath+"/030013101154183I20143Z000.xls")));
                POIFSFileSystem fs5=new POIFSFileSystem(new FileInputStream(new File(excePath+"/030013101154183J20143Z000.xls")));
                
                String name1="030013101154183F"+off.getYear()+"3Z000.xls";
                String name2="030013101154183G"+off.getYear()+"3Z000.xls";
                String name3="030013101154183H"+off.getYear()+"3Z000.xls";
                String name4="030013101154183I"+off.getYear()+"3Z000.xls";
                String name5="030013101154183J"+off.getYear()+"3Z000.xls";
                
            /*-----------------------操作识别客户表----------------------------------**/    
                
                HSSFWorkbook wb1=new HSSFWorkbook(fs1);
                HSSFSheet sheet1=wb1.getSheetAt(0);
                
                HSSFCell c11=sheet1.getRow(1).getCell((short) 5);
                c11.setCellValue(off.getYear());
                
                HSSFCell c12=sheet1.getRow(1).getCell((short) 7);
                c12.setCellValue(off.getQuarter());
                
                HSSFCell c13=sheet1.getRow(2).getCell((short) 7);
                if(off.getData30().equals("0")){
                    c13.setCellValue("是");
                }else {
                    c13.setCellValue("否");
                }
                
                //制表人
                sheet1.getRow(3).getCell((short) 1).setCellValue(user.getName());
                //联系电话
                sheet1.getRow(3).getCell((short) 3).setCellValue(user.getTelphone());
                //对公总数
                sheet1.getRow(6).getCell((short) 3).setCellValue(off.getData1());
                //对公通过第三方识别数
                sheet1.getRow(8).getCell((short) 3).setCellValue(off.getData2());
                //对公与离岸中心有关的
                sheet1.getRow(9).getCell((short) 3).setCellValue(off.getData21());
                //对公受益人数
                sheet1.getRow(10).getCell((short) 3).setCellValue(off.getData22());
                
                HSSFCell c14=sheet1.getRow(18).getCell((short) 3);
                c14.setCellValue(off.getData3());
                
                HSSFCell c15=sheet1.getRow(21).getCell((short) 3);
                c15.setCellValue(off.getData18());
                //其中他人代理的
                sheet1.getRow(22).getCell((short)3).setCellValue(off.getData24());
                
                HSSFCell c16=sheet1.getRow(23).getCell((short) 3);
                c16.setCellValue(off.getData17());
                
                //其中他人代理的
                sheet1.getRow(24).getCell((short)3).setCellValue(off.getData25());
                
                HSSFCell c17=sheet1.getRow(32).getCell((short) 3);
                c17.setCellValue(off.getData30());
                
                
                zos.putNextEntry(new ZipEntry(name1));
//                zos.write(wb1.getBytes());
                wb1.write(zos);
                
//                out=new FileOutputStream("E://"+name1);
//                wb1.write(out);
//                out.close();
                /*----------------------操作重新识别客户-----------------------------------**/    
                HSSFWorkbook wb2=new HSSFWorkbook(fs2);
                HSSFSheet sheet2=wb2.getSheetAt(0);
                
                HSSFCell c21=sheet2.getRow(1).getCell((short) 5);
                c21.setCellValue(off.getYear());
                
                HSSFCell c22=sheet2.getRow(1).getCell((short) 7);
                c22.setCellValue(off.getQuarter());
                
                HSSFCell c23=sheet2.getRow(2).getCell((short) 7);
                if(off.getData31().equals("0")&&off.getData33().equals("0")){
                    c23.setCellValue("是");
                }else {
                    c23.setCellValue("否");
                }
                //制表人
                sheet2.getRow(3).getCell((short) 1).setCellValue(user.getName());
                //联系电话
                sheet2.getRow(3).getCell((short) 3).setCellValue(user.getTelphone());
                
                sheet2.getRow(7).getCell((short) 1).setCellValue(off.getData4());
                sheet2.getRow(7).getCell((short) 2).setCellValue(off.getData5());
                
                
                HSSFCell c24=sheet2.getRow(7).getCell((short) 3);
                c24.setCellValue(off.getData6());
                
                sheet2.getRow(7).getCell((short) 4).setCellValue(off.getData26());
                sheet2.getRow(7).getCell((short) 5).setCellValue(off.getData27());
                
                //其中查实
                sheet2.getRow(8).getCell((short) 1).setCellValue(off.getData4());
                sheet2.getRow(8).getCell((short) 2).setCellValue(off.getData5());
                sheet2.getRow(8).getCell((short) 3).setCellType(1);
                sheet2.getRow(8).getCell((short) 3).setCellValue(off.getData6());
                sheet2.getRow(8).getCell((short) 4).setCellValue(off.getData26());
                sheet2.getRow(8).getCell((short) 5).setCellValue(off.getData27());
                
                
                sheet2.getRow(13).getCell((short) 1).setCellValue(off.getData7());
                sheet2.getRow(13).getCell((short) 2).setCellValue(off.getData8());
                HSSFCell c25=sheet2.getRow(13).getCell((short) 3);
                c25.setCellValue(off.getData9());
                sheet2.getRow(13).getCell((short) 4).setCellValue(off.getData28());
                sheet2.getRow(13).getCell((short) 5).setCellValue(off.getData29());
                
                //其中查实
                sheet2.getRow(14).getCell((short) 1).setCellValue(off.getData7());
                sheet2.getRow(14).getCell((short) 2).setCellValue(off.getData8());
                sheet2.getRow(14).getCell((short) 3).setCellType(1);
                sheet2.getRow(14).getCell((short) 3).setCellValue(off.getData9());
                sheet2.getRow(14).getCell((short) 4).setCellValue(off.getData28());
                sheet2.getRow(14).getCell((short) 5).setCellValue(off.getData29());
                
                
                sheet2.getRow(17).getCell((short) 1).setCellValue(off.getData31());
                sheet2.getRow(17).getCell((short) 2).setCellType(1);
                sheet2.getRow(17).getCell((short) 2).setCellValue(off.getData32());
                HSSFCell c26=sheet2.getRow(17).getCell((short) 3);
                System.out.println("type:"+c26.getCellType());
                c26.setCellType(1);
                c26.setCellValue(off.getData33());
                sheet2.getRow(17).getCell((short) 4).setCellType(1);
                sheet2.getRow(17).getCell((short) 4).setCellValue(off.getData34());
                sheet2.getRow(17).getCell((short) 5).setCellType(1);
                sheet2.getRow(17).getCell((short) 5).setCellValue(off.getData35());
                
                
                //其中查实
                sheet2.getRow(18).getCell((short) 1).setCellValue(off.getData31());
                sheet2.getRow(18).getCell((short) 2).setCellType(1);
                sheet2.getRow(18).getCell((short) 2).setCellValue(off.getData32());
                sheet2.getRow(18).getCell((short) 3).setCellType(1);
                sheet2.getRow(18).getCell((short) 3).setCellValue(off.getData33());
                sheet2.getRow(18).getCell((short) 4).setCellType(1);
                sheet2.getRow(18).getCell((short) 4).setCellValue(off.getData34());
                sheet2.getRow(18).getCell((short) 5).setCellType(1);
                sheet2.getRow(18).getCell((short) 5).setCellValue(off.getData35());
                
                zos.putNextEntry(new ZipEntry(name2));
//                zos.write(wb2.getBytes());
                wb2.write(zos);
//                out=new FileOutputStream("E://"+name2);
                
//                wb2.write(out);
//                out.close();
                /*----------------------操作涉及可疑交易识别情况-----------------------------------**/    
                HSSFWorkbook wb3=new HSSFWorkbook(fs3);
                HSSFSheet sheet3=wb3.getSheetAt(0);
                
                HSSFCell c31=sheet3.getRow(1).getCell((short) 5);
                c31.setCellValue(off.getYear());
                
                HSSFCell c32=sheet3.getRow(1).getCell((short) 7);
                c32.setCellValue(off.getQuarter());
                
                HSSFCell c33=sheet3.getRow(2).getCell((short) 7);
                c33.setCellValue("是");
//                if(off.getData10().equals("0")&&off.getData12().equals("0")){
//                    c33.setCellValue("是");
//                }else {
//                    c33.setCellValue("否");
//                }
                //制表人
                sheet3.getRow(3).getCell((short) 1).setCellValue(user.getName());
                //联系电话
                sheet3.getRow(3).getCell((short) 3).setCellValue(user.getTelphone());
//                HSSFCell c34=sheet3.getRow(7).getCell((short) 0);
//                c34.setCellValue(off.getData10());    
                
//                HSSFCell c35=sheet3.getRow(7).getCell((short) 3);
//                c35.setCellValue(off.getData12());
                
                zos.putNextEntry(new ZipEntry(name3));
//                zos.write(wb3.getBytes());
                wb3.write(zos);
                
//                out=new FileOutputStream("E://"+name3);
//                wb3.write(out);
//                out.close();
                /*----------------------金融机构可疑交易报告情况统计表-----------------------------------**/
                HSSFWorkbook wb4=new HSSFWorkbook(fs4);
                HSSFSheet sheet4=wb4.getSheetAt(0);
                
                HSSFCell c41=sheet4.getRow(1).getCell((short) 5);
                c41.setCellValue(off.getYear());
                
                HSSFCell c42=sheet4.getRow(1).getCell((short) 7);
                c42.setCellValue(off.getQuarter());
                
                HSSFCell c43=sheet4.getRow(2).getCell((short) 7);
                if(off.getData13().equals("0")&&off.getData14().equals("0")&&off.getData15().equals("0")&&off.getData16().equals("0")){
                    c43.setCellValue("是");
                }else {
                    c43.setCellValue("否");
                }
                //制表人
                sheet4.getRow(3).getCell((short) 1).setCellValue(user.getName());
                //联系电话
                sheet4.getRow(3).getCell((short) 3).setCellValue(user.getTelphone());
                
//                HSSFCell c44=sheet4.getRow(5).getCell((short) 2);
//                c44.setCellValue(off.getData19());
                
//                HSSFCell c45=sheet4.getRow(5).getCell((short) 4);
//                c45.setCellValue(off.getData20());
//                
                sheet4.getRow(10).getCell((short) 1).setCellValue(off.getData13());
                sheet4.getRow(10).getCell((short) 2).setCellValue(off.getData14());
                HSSFCell c46=sheet4.getRow(10).getCell((short) 3);
                c46.setCellValue(off.getData15());
//                
                HSSFCell c47=sheet4.getRow(10).getCell((short) 4);
                c47.setCellValue(off.getData16());
                
                zos.putNextEntry(new ZipEntry(name4));
//                zos.write(wb4.getBytes());
                wb4.write(zos);
//                out=new FileOutputStream("E://"+name4);
//                wb4.write(out);
//                out.close();
                /*----------------------金融机构协助公安机关、其他机关打击洗钱活动情况-----------------------------------**/
                HSSFWorkbook wb5=new HSSFWorkbook(fs5);
                HSSFSheet sheet5=wb5.getSheetAt(0);
                
                HSSFCell c51=sheet5.getRow(1).getCell((short) 5);
                c51.setCellValue(off.getYear());
                
                HSSFCell c52=sheet5.getRow(1).getCell((short) 7);
                c52.setCellValue(off.getQuarter());
                
                //制表人
                sheet5.getRow(3).getCell((short) 1).setCellValue(user.getName());
                //联系电话
                sheet5.getRow(3).getCell((short) 3).setCellValue(user.getTelphone());
                zos.putNextEntry(new ZipEntry(name5));
//                zos.write(wb5.getBytes());
                wb5.write(zos);
//                out=new FileOutputStream("E://"+name5);
//                wb5.write(out);
//                out.close();
                zos.flush();
                zos.closeEntry();
                zos.close();
                
                
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            request.setAttribute("data",off);

    }

 

转载于:https://www.cnblogs.com/joyblabla/p/4800442.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值