导出EXCEL上传 服务器 添加压缩包,获取文件 大小

package net.joystart.excelTask;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.jcraft.jsch.ChannelSftp;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFeatures;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import net.joystart.common.util.ConfigUtil;
import net.joystart.common.util.SftpUtil;
import net.joystart.common.util.ZipUtil;
import net.joystart.customer.entity.Customer;
import net.joystart.customer.service.ICustomerService;
import net.joystart.excelTask.entity.CownExcel;
import net.joystart.order.entity.Order;
import net.joystart.order.service.IOrderService;
import net.joystart.vehicle.controller.VehicleController;
import net.joystart.vehicle.entity.Parkinglot;
import net.joystart.vehicle.entity.Vehicle;
import net.joystart.vehicle.service.IParkinglotService;
import net.joystart.vehicle.service.IVehicleService;

@Component("ExcelController")
public class ExcelController {
    @Resource
    private ICustomerService customerService;

    @Resource
    private IParkinglotService parkinglotService;

    @Resource
    IVehicleService vehicleService;
   @Resource
    IOrderService orderService;
    /**
     * 订单自动服务
     */
    public void customerExcel() {
        Map<String, Object> params = new HashMap<String, Object>();

        List<Customer> customerList = customerService.list(params);
        exportExcel("会员信息.xls", customerList);
    }

    /** */
    /**
     * 导出数据为XLS格式
     *
     * @param fileName
     *            文件的名称,可以设为绝对路径,也可以设为相对路径
     * @param content
     *            数据的内容
     */
    private void exportExcel(String fileName, List<Customer> customers) {
        WritableWorkbook wwb;
        FileOutputStream fos;
        try {
            String savePath = ConfigUtil.pro.get("excelPath").toString();
            Date date = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
            String newDate = dateFormat.format(date);
            File f = new File(savePath);
            f = new File(f, newDate+".xls");
            //f.createNewFile();

            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableSheet ws = wwb.createSheet("会员列表", 0); // 创建一个工作表

            // 设置单元格的文字格式
            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            ws.setRowView(1, 500);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式
            // 设置标题行
            int rowsCount = customers.size();
            // 填充数据的内容
            Customer customer;
            for (int i = 0; i < rowsCount; i++) {
                customer = customers.get(i);

                WritableCellFeatures x;
                ws.addCell(new Label(0, i + 0, customer.getName(), wcf));
                ws.addCell(new Label(1, i + 0, customer.getMobile(), wcf));
                double orderCost = customer.getRemainmoney() == null ? 0.00 : customer.getRemainmoney().doubleValue();
                jxl.write.Number labelOrderCost = new jxl.write.Number(2, i + 1, orderCost, wcfN); // 格式化数值
                ws.addCell(labelOrderCost);
            }
            wwb.write();
            wwb.close();
            FileInputStream fileInputStream = new FileInputStream(new File(fileName));
            Date dt = new Date();// 如果不需要格式,可直接用dt,dt就是当前系统时间
            DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// 设置显示格式
            String nowTime = "";
            nowTime = df.format(dt);// 用DateFormat的format()方法在dt中获取并以yyyy/MM/dd
            fileName = "用户信息" + nowTime + ".xls";
            // 保存EXCEL内容
            CownExcel ce = new CownExcel();
            ce.setDownloaddate(new Date());
            ce.setUrl(f.getPath());
            ce.setFileName(newDate+".xls");
            customerService.insertSelective(ce);

        } catch (IOException e) {
        } catch (RowsExceededException e) {
        } catch (WriteException e) {
        }
    }

    public SftpUtil getSFTPChannel() {
        return new SftpUtil();
    }

    // 导出运管需要的数据
    public void exportTransportationExcel() {
        WritableWorkbook wwb;
        FileOutputStream fos;
        String savePath = ConfigUtil.pro.get("excelPath").toString();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_DEP_"+newDate+".csv");

        try {

            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            WritableSheet ws = wwb.createSheet("租赁企业信息", 0); // 创建一个工作表
            ws.setRowView(1, 500);
            /// 添加企业信息////////////////////////////////////////////////////////////////
            // 设置标题行

            WritableCellFeatures x;
            ws.addCell(new Label(0, 0, "北京巴歌汽车租赁有限公司", wcf));
            ws.addCell(new Label(1, 0, "001615", wcf));
            ws.addCell(new Label(2, 0, "北京", wcf));
            ws.addCell(new Label(3, 0, "北京市", wcf));
            ////////////////////////////////////////////////////////////////////////////
            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
            String lsize = String.valueOf(f.length());
            f.delete();
            exportTransportationExcelNew(lsize);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (RowsExceededException e) {
            e.printStackTrace();
        } catch (WriteException e) {
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private void exportTransportationExcelNew(String lsize){
        WritableWorkbook wwb;
        FileOutputStream fos;

        String savePath = ConfigUtil.pro.get("excelPath").toString();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_DEP_"+newDate+"_"+lsize+"" + ".csv");

        try {

            // f.createNewFile();
            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            WritableSheet ws = wwb.createSheet("租赁企业信息", 0); // 创建一个工作表
            ws.setRowView(1, 500);
            /// 添加企业信息////////////////////////////////////////////////////////////////

            WritableCellFeatures x;
            ws.addCell(new Label(0, 0, "北京巴歌汽车租赁有限公司", wcf));
            ws.addCell(new Label(1, 0, "001615", wcf));
            ws.addCell(new Label(2, 0, "北京", wcf));
            ws.addCell(new Label(3, 0, "北京市", wcf));

            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
        } catch (IOException e) {
        } catch (RowsExceededException e) {
        } catch (WriteException e) {
        }

        ///获取文件大小/////////////////////////////////////////////////////////////////////

        ///添加压缩功能/////////////////////////////////////////////////////////////////////
        String zipName = "COL_DEP_"+newDate+"_"+lsize+".zip";
        File fZ = new File(savePath);
        fZ = new File(fZ, zipName);
        ZipUtil zip =new ZipUtil();
        try {
            zip.zip(fZ.getPath(), f.getPath());
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        String zipNameNew = "COL_DEP_"+newDate+"_"+fZ.length()+".zip";
        File fZNew = new File(savePath);
        fZNew = new File(fZNew, zipNameNew);
        fileupload(fZ.getPath(),fZNew.getPath());        fZ.delete();//删除旧压缩包

        // 调用sftp开始上传文件//////////////////////////////////////////////////////////////
        VehicleController vehicleController = new VehicleController();
        SftpUtil channel = vehicleController.getSFTPChannel();
        try {
            ChannelSftp chSftp = channel.getChannel(60000);
            String strSaveUrl = "/COLLECTION/" + fZ.getName();
            chSftp.put(fZ.getPath(), strSaveUrl, ChannelSftp.OVERWRITE);
            chSftp.quit();
            channel.closeChannel();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ////////////////////////////////////////////////////////////////////////////////
        ExcelMethod1();
        ExcelMethod2();
        ExcelMethod3();
        ExcelMethod4();
        ExcelMethod5();
    }

    private void ExcelMethod1()
    {
        WritableWorkbook wwb;
        FileOutputStream fos;
        String savePath = ConfigUtil.pro.get("excelPath").toString();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_DEP_"+newDate+"" + ".csv");
        try {

            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            WritableSheet ws = wwb.createSheet("租赁门店信息", 0); // 创建一个工作表
            ws.setRowView(1, 500);
            /// 租赁门店信息////////////////////////////////////////////////////////////////
            List<Parkinglot> parklotList = parkinglotService.findAllParkingLotAndBranch();

            for (int i = 0; i < parklotList.size(); i++) {
                Parkinglot parking = parklotList.get(i);

                ws.addCell(new Label(0, i + 0, parking.getName(), wcf));
                ws.addCell(new Label(1, i + 0, "北京巴歌汽车租赁有限公司", wcf));
                ws.addCell(new Label(2, i + 0, parking.getLongitude(), wcf));
                ws.addCell(new Label(3, i + 0, parking.getLatitude(), wcf));
                ws.addCell(new Label(4, i + 0, " ", wcf));
                ws.addCell(new Label(5, i + 0, parking.getPosition(), wcf));
                ws.addCell(new Label(6, i + 0, " ", wcf));
                ws.addCell(new Label(7, i + 0, " ", wcf));
            }

            ////////////////////////////////////////////////////////////////////////////
            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
            String lsize = String.valueOf(f.length());
            f.delete();
            ExcelMethod1New(lsize);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (RowsExceededException e) {
            e.printStackTrace();
        } catch (WriteException e) {
            e.printStackTrace();
        } catch (Exception e1) {
            e1.printStackTrace();
        }

    }
    private void ExcelMethod1New(String lsize){
        WritableWorkbook wwb;
        FileOutputStream fos;

        String savePath = ConfigUtil.pro.get("excelPath").toString();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_DEP_"+newDate+"_"+lsize+"" + ".csv");

        try {

            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            WritableSheet ws = wwb.createSheet("租赁门店信息", 0); // 创建一个工作表
            ws.setRowView(1, 500);
            /// 租赁门店信息////////////////////////////////////////////////////////////////
            List<Parkinglot> parklotList = parkinglotService.findAllParkingLotAndBranch();

            for (int i = 0; i < parklotList.size(); i++) {
                Parkinglot parking = parklotList.get(i);

                ws.addCell(new Label(0, i + 0, parking.getName(), wcf));
                ws.addCell(new Label(1, i + 0, "北京巴歌汽车租赁有限公司", wcf));
                ws.addCell(new Label(2, i + 0, parking.getLongitude(), wcf));
                ws.addCell(new Label(3, i + 0, parking.getLatitude(), wcf));
                ws.addCell(new Label(4, i + 0, " ", wcf));
                ws.addCell(new Label(5, i + 0, parking.getPosition(), wcf));
                ws.addCell(new Label(6, i + 0, " ", wcf));
                ws.addCell(new Label(7, i + 0, " ", wcf));
            }

            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (RowsExceededException e) {
            e.printStackTrace();
        } catch (WriteException e) {
            e.printStackTrace();
        }

        ///添加压缩功能/////////////////////////////////////////////////////////////////////
        String zipName = "COL_DEP_"+newDate+"_"+lsize+".zip";
        File fZ = new File(savePath);
        fZ = new File(fZ, zipName);
        ZipUtil zip =new ZipUtil();
        try {
            zip.zip(fZ.getPath(), f.getPath());
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        String zipNameNew = "COL_DEP_"+newDate+"_"+fZ.length()+".zip";
        File fZNew = new File(savePath);
        fZNew = new File(fZNew, zipNameNew);
        fileupload(fZ.getPath(),fZNew.getPath());     fZ.delete();//删除旧压缩包
        // 调用sftp开始上传文件//////////////////////////////////////////////////////////////
        VehicleController vehicleController = new VehicleController();
        SftpUtil channel = vehicleController.getSFTPChannel();
        try {
            ChannelSftp chSftp = channel.getChannel(60000);
            String strSaveUrl = "/COLLECTION/" + fZ.getName();
            chSftp.put(fZ.getPath(), strSaveUrl, ChannelSftp.OVERWRITE);
            chSftp.quit();
            channel.closeChannel();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ////////////////////////////////////////////////////////////////////////////////
    }

    private void ExcelMethod2()
    {
        WritableWorkbook wwb;
        FileOutputStream fos;
        String savePath = ConfigUtil.pro.get("excelPath").toString();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_CAR_"+newDate+"" + ".csv");
        try {

            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            WritableSheet ws = wwb.createSheet("租赁车辆基本信息", 0); // 创建一个工作表
            ws.setRowView(1, 500);

            /// 租赁门店信息////////////////////////////////////////////////////////////////
            List<Vehicle> vehicleList = vehicleService.selectAllVehicle();

            for (int i = 0; i < vehicleList.size(); i++) {
                Vehicle vehicle = vehicleList.get(i);

                ws.addCell(new Label(0, i + 0, vehicle.getPlatenumber(), wcf));
                ws.addCell(new Label(1, i + 0, vehicle.getEngineno(), wcf));
                ws.addCell(new Label(2, i + 0, vehicle.getVin(), wcf));
                ws.addCell(new Label(3, i + 0, vehicle.getUploadImgUrl(), wcf));
                ws.addCell(new Label(4, i + 0, vehicle.getUploadImgUrlTwo(), wcf));
                ws.addCell(new Label(5, i + 0, vehicle.getCarcolor(), wcf));
                ws.addCell(new Label(6, i + 0, vehicle.getDrivinglicenseurl(), wcf));
                ws.addCell(new Label(7, i + 0, " ", wcf));
                ws.addCell(new Label(8, i + 0, " ", wcf));
                ws.addCell(new Label(9, i + 0, "5", wcf));
                ws.addCell(new Label(10, i + 0, " ", wcf));
                ws.addCell(new Label(11, i + 0, vehicle.getCreatedate()==null?"":sdf.format(vehicle.getCreatedate()), wcf));
                ws.addCell(new Label(12, i + 0, " ", wcf));
                ws.addCell(new Label(13, i + 0, " ", wcf));
            }
            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
            String lsize = String.valueOf(f.length());
            f.delete();
            ExcelMethod2New(lsize);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (RowsExceededException e) {
            e.printStackTrace();
        } catch (WriteException e) {
            e.printStackTrace();
        } catch (Exception e1) {
            e1.printStackTrace();
        }

    }
    private void ExcelMethod2New(String lsize){
        WritableWorkbook wwb;
        FileOutputStream fos;

        String savePath = ConfigUtil.pro.get("excelPath").toString();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_CAR_"+newDate+"_"+lsize+"" + ".csv");
        try {

            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            WritableSheet ws = wwb.createSheet("租赁车辆基本信息", 0); // 创建一个工作表
            ws.setRowView(1, 500);

            /// 租赁门店信息////////////////////////////////////////////////////////////////
            List<Vehicle> vehicleList = vehicleService.selectAllVehicle();

            for (int i = 0; i < vehicleList.size(); i++) {
                Vehicle vehicle = vehicleList.get(i);

                ws.addCell(new Label(0, i + 0, vehicle.getPlatenumber(), wcf));
                ws.addCell(new Label(1, i + 0, vehicle.getEngineno(), wcf));
                ws.addCell(new Label(2, i + 0, vehicle.getVin(), wcf));
                ws.addCell(new Label(3, i + 0, vehicle.getUploadImgUrl(), wcf));
                ws.addCell(new Label(4, i + 0, vehicle.getUploadImgUrlTwo(), wcf));
                ws.addCell(new Label(5, i + 0, vehicle.getCarcolor(), wcf));
                ws.addCell(new Label(6, i + 0, vehicle.getDrivinglicenseurl(), wcf));
                ws.addCell(new Label(7, i + 0, " ", wcf));
                ws.addCell(new Label(8, i + 0, " ", wcf));
                ws.addCell(new Label(9, i + 0, "5", wcf));
                ws.addCell(new Label(10, i + 0, " ", wcf));
                ws.addCell(new Label(11, i + 0, vehicle.getCreatedate()==null?"":sdf.format(vehicle.getCreatedate()), wcf));
                ws.addCell(new Label(12, i + 0, " ", wcf));
                ws.addCell(new Label(13, i + 0, " ", wcf));
            }
            ////////////////////////////////////////////////////////////////////////////

            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (RowsExceededException e) {
            e.printStackTrace();
        } catch (WriteException e) {
            e.printStackTrace();
        }

        ///添加压缩功能/////////////////////////////////////////////////////////////////////
        String zipName = "COL_CAR_"+newDate+"_"+lsize+".zip";
        File fZ = new File(savePath);
        fZ = new File(fZ, zipName);
        ZipUtil zip =new ZipUtil();
        try {
            zip.zip(fZ.getPath(), f.getPath());
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        //新压缩包名称
        String zipNameNew = "COL_CAR_"+newDate+"_"+fZ.length()+".zip";
        File fZNew = new File(savePath);
        fZNew = new File(fZNew, zipNameNew);
        fileupload(fZ.getPath(),fZNew.getPath());
        // 调用sftp开始上传文件//////////////////////////////////////////////////////////////
        VehicleController vehicleController = new VehicleController();
        SftpUtil channel = vehicleController.getSFTPChannel();
        try {
            ChannelSftp chSftp = channel.getChannel(60000);
            String strSaveUrl = "/COLLECTION/" + fZ.getName();
            chSftp.put(fZ.getPath(), strSaveUrl, ChannelSftp.OVERWRITE);
            chSftp.quit();
            channel.closeChannel();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ////////////////////////////////////////////////////////////////////////////////
    }

    private void ExcelMethod3()
    {
        WritableWorkbook wwb;
        FileOutputStream fos;
        String savePath = ConfigUtil.pro.get("excelPath").toString();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_ASS_"+newDate+"" + ".csv");

        try {

            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            WritableSheet ws = wwb.createSheet("租赁车辆归属信息", 0); // 创建一个工作表
            ws.setRowView(1, 500);

            /// 租赁门店信息////////////////////////////////////////////////////////////////
            List<Vehicle> vehicleList = vehicleService.selectAllVehicleSite();

            for (int i = 0; i < vehicleList.size(); i++) {
                Vehicle vehicle = vehicleList.get(i);

                ws.addCell(new Label(0, i + 0, vehicle.getPlatenumber(), wcf));
                ws.addCell(new Label(1, i + 0, " ", wcf));
                ws.addCell(new Label(2, i + 0, StringUtils.isBlank(vehicle.getUploadImgUrlTwo())
                        ? vehicle.getUploadImgUrl() : vehicle.getUploadImgUrlTwo(), wcf));
                ws.addCell(new Label(3, i + 0, vehicle.getDrivinglicenseurl(), wcf));
            }

            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
            String lsize = String.valueOf(f.length());
            f.delete();
            ExcelMethod3New(lsize);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (RowsExceededException e) {
            e.printStackTrace();
        } catch (WriteException e) {
            e.printStackTrace();
        }  catch (Exception e1) {
            e1.printStackTrace();
        }

    }
    private void ExcelMethod3New(String lsize){
        WritableWorkbook wwb;
        FileOutputStream fos;

        String savePath = ConfigUtil.pro.get("excelPath").toString();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_ASS_"+newDate+"_"+lsize+"" + ".csv");

        try {

            // f.createNewFile();
            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            WritableSheet ws = wwb.createSheet("租赁车辆归属信息", 0); // 创建一个工作表
            ws.setRowView(1, 500);

            /// 租赁门店信息////////////////////////////////////////////////////////////////
            List<Vehicle> vehicleList = vehicleService.selectAllVehicleSite();

            for (int i = 0; i < vehicleList.size(); i++) {
                Vehicle vehicle = vehicleList.get(i);

                ws.addCell(new Label(0, i + 0, vehicle.getPlatenumber(), wcf));
                ws.addCell(new Label(1, i + 0, " ", wcf));
                ws.addCell(new Label(2, i + 0, StringUtils.isBlank(vehicle.getUploadImgUrlTwo())
                        ? vehicle.getUploadImgUrl() : vehicle.getUploadImgUrlTwo(), wcf));
                ws.addCell(new Label(3, i + 0, vehicle.getDrivinglicenseurl(), wcf));
            }
            ////////////////////////////////////////////////////////////////////////////

            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (RowsExceededException e) {
            e.printStackTrace();
        } catch (WriteException e) {
            e.printStackTrace();
        }

        ///添加压缩功能/////////////////////////////////////////////////////////////////////
        String zipName = "COL_ASS_"+newDate+"_"+lsize+".zip";
        File fZ = new File(savePath);
        fZ = new File(fZ, zipName);
        ZipUtil zip =new ZipUtil();
        try {
            zip.zip(fZ.getPath(), f.getPath());
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        //新压缩包名称
        String zipNameNew = "COL_ASS_"+newDate+"_"+fZ.length()+".zip";
        File fZNew = new File(savePath);
        fZNew = new File(fZNew, zipNameNew);
        fileupload(fZ.getPath(),fZNew.getPath());
        // 调用sftp开始上传文件//////////////////////////////////////////////////////////////
        VehicleController vehicleController = new VehicleController();
        SftpUtil channel = vehicleController.getSFTPChannel();
        try {
            ChannelSftp chSftp = channel.getChannel(60000);
            String strSaveUrl = "/COLLECTION/" + fZ.getName();
            chSftp.put(fZ.getPath(), strSaveUrl, ChannelSftp.OVERWRITE);
            chSftp.quit();
            channel.closeChannel();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private void ExcelMethod4()
    {
        WritableWorkbook wwb;
        FileOutputStream fos;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String savePath = ConfigUtil.pro.get("excelPath").toString();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_CON_"+newDate+"" + ".csv");
        try {

            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            WritableSheet ws = wwb.createSheet("租赁合同信息", 0); // 创建一个工作表
            ws.setRowView(1, 500);

            /// 租赁门店信息////////////////////////////////////////////////////////////////
            Map<String, Object> params = new HashMap<String, Object>();

            Calendar calendar_as = Calendar.getInstance();
            calendar_as.setTime(new Date());

            Calendar calendar_ST = Calendar.getInstance();
            calendar_ST.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
                    calendar_as.get(Calendar.DATE) - 1, 0, 0, 0);
            calendar_ST.set(Calendar.MILLISECOND, 0);

            Calendar calendar_ET = Calendar.getInstance();
            calendar_ET.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
                    calendar_as.get(Calendar.DATE), 0, 0, 0);
            calendar_ET.set(Calendar.MILLISECOND, 0);

            SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");

            params.put("_startDate", dft.format(calendar_ST.getTime()));
            params.put("_endDate", dft.format(calendar_ET.getTime()));
            List<Order> orderList = orderService.selectAllOrders(params);

            for (int i = 0; i < orderList.size(); i++) {
                Order order = orderList.get(i);

                ws.addCell(new Label(0, i + 0, order.getOrderno(), wcf));
                ws.addCell(new Label(1, i + 0, order.getPlatenumber(), wcf));
                ws.addCell(new Label(2, i + 0, " ", wcf));
                ws.addCell(new Label(3, i + 0, " ", wcf));
                ws.addCell(new Label(4, i + 0, " ", wcf));
                ws.addCell(new Label(5, i + 0, " ", wcf));
                ws.addCell(new Label(6, i + 0, " ", wcf));
                ws.addCell(new Label(7, i + 0, order.getCreatedate()==null? " ":sdf.format(order.getCreatedate()), wcf));
                ws.addCell(new Label(8, i + 0,
                        order.getReturnvehicledate() == null ? " " : sdf.format(order.getReturnvehicledate()), wcf));
                ws.addCell(new Label(9, i + 0, StringUtils.isBlank(order.getRentBranchName()) ? order.getRentParkName()
                        : order.getRentBranchName(), wcf));
                ws.addCell(new Label(10, i + 0, " ", wcf));
                ws.addCell(new Label(11, i + 0, order.getCreatedate()==null?"":sdf.format(order.getCreatedate()), wcf));
                ws.addCell(new Label(12, i + 0, order.getCustomerName(), wcf));
                ws.addCell(new Label(13, i + 0, order.getInvitationCode(), wcf));
                ws.addCell(new Label(14, i + 0, " ", wcf));
                ws.addCell(new Label(15, i + 0, " ", wcf));
                ws.addCell(new Label(16, i + 0, " ", wcf));
            }
            ////////////////////////////////////////////////////////////////////////////

            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
            String lsize = String.valueOf(f.length());
            f.delete();
            ExcelMethod4New(lsize);
        } catch (IOException e) {
        } catch (RowsExceededException e) {
        } catch (WriteException e) {
        } catch (Exception e1) {
            e1.printStackTrace();
        }

    }
    private void ExcelMethod4New(String lsize){
        WritableWorkbook wwb;
        FileOutputStream fos;

        String savePath = ConfigUtil.pro.get("excelPath").toString();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_CON_"+newDate+"_"+lsize+"" + ".csv");

        try {

            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            WritableSheet ws = wwb.createSheet("租赁合同信息", 0); // 创建一个工作表
            ws.setRowView(1, 500);

            /// 租赁门店信息////////////////////////////////////////////////////////////////
            Map<String, Object> params = new HashMap<String, Object>();

            Calendar calendar_as = Calendar.getInstance();
            calendar_as.setTime(new Date());

            Calendar calendar_ST = Calendar.getInstance();
            calendar_ST.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
                    calendar_as.get(Calendar.DATE) - 1, 0, 0, 0);
            calendar_ST.set(Calendar.MILLISECOND, 0);

            Calendar calendar_ET = Calendar.getInstance();
            calendar_ET.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
                    calendar_as.get(Calendar.DATE), 0, 0, 0);
            calendar_ET.set(Calendar.MILLISECOND, 0);

            SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");

            params.put("_startDate", dft.format(calendar_ST.getTime()));
            params.put("_endDate", dft.format(calendar_ET.getTime()));
            List<Order> orderList = orderService.selectAllOrders(params);

            for (int i = 0; i < orderList.size(); i++) {
                Order order = orderList.get(i);

                ws.addCell(new Label(0, i + 0, order.getOrderno(), wcf));
                ws.addCell(new Label(1, i + 0, order.getPlatenumber(), wcf));
                ws.addCell(new Label(2, i + 0, " ", wcf));
                ws.addCell(new Label(3, i + 0, " ", wcf));
                ws.addCell(new Label(4, i + 0, " ", wcf));
                ws.addCell(new Label(5, i + 0, " ", wcf));
                ws.addCell(new Label(6, i + 0, " ", wcf));
                ws.addCell(new Label(7, i + 0, order.getCreatedate()==null? " ":sdf.format(order.getCreatedate()), wcf));
                ws.addCell(new Label(8, i + 0,
                        order.getReturnvehicledate() == null ? " " : sdf.format(order.getReturnvehicledate()), wcf));
                ws.addCell(new Label(9, i + 0, StringUtils.isBlank(order.getRentBranchName()) ? order.getRentParkName()
                        : order.getRentBranchName(), wcf));
                ws.addCell(new Label(10, i + 0, " ", wcf));
                ws.addCell(new Label(11, i + 0, order.getCreatedate()==null?"":sdf.format(order.getCreatedate()), wcf));
                ws.addCell(new Label(12, i + 0, order.getCustomerName(), wcf));
                ws.addCell(new Label(13, i + 0, order.getInvitationCode(), wcf));
                ws.addCell(new Label(14, i + 0, " ", wcf));
                ws.addCell(new Label(15, i + 0, " ", wcf));
                ws.addCell(new Label(16, i + 0, " ", wcf));
            }
            ////////////////////////////////////////////////////////////////////////////

            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
        } catch (IOException e) {
        } catch (RowsExceededException e) {
        } catch (WriteException e) {
        }
        ///添加压缩功能/////////////////////////////////////////////////////////////////////
        String zipName = "COL_CON_"+newDate+"_"+lsize+".zip";
        File fZ = new File(savePath);
        fZ = new File(fZ, zipName);
        ZipUtil zip =new ZipUtil();
        try {
            zip.zip(fZ.getPath(), f.getPath());
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        //新压缩包名称
        String zipNameNew = "COL_CON_"+newDate+"_"+fZ.length()+".zip";
        File fZNew = new File(savePath);
        fZNew = new File(fZNew, zipNameNew);
        fileupload(fZ.getPath(),fZNew.getPath());

        // 调用sftp开始上传文件//////////////////////////////////////////////////////////////
        VehicleController vehicleController = new VehicleController();
        SftpUtil channel = vehicleController.getSFTPChannel();
        try {
            ChannelSftp chSftp = channel.getChannel(60000);
            String strSaveUrl = "/COLLECTION/" + fZ.getName();
            chSftp.put(fZ.getPath(), strSaveUrl, ChannelSftp.OVERWRITE);
            chSftp.quit();
            channel.closeChannel();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private void ExcelMethod5()
    {
        WritableWorkbook wwb;
        FileOutputStream fos;
        String savePath = ConfigUtil.pro.get("excelPath").toString();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_WAY_"+newDate+"" + ".csv");

        try {

            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            WritableSheet ws = wwb.createSheet("租赁结算单", 0); // 创建一个工作表
            ws.setRowView(1, 500);

            /// 租赁门店信息////////////////////////////////////////////////////////////////
            Map<String, Object> params = new HashMap<String, Object>();

            Calendar calendar_as = Calendar.getInstance();
            calendar_as.setTime(new Date());

            Calendar calendar_ST = Calendar.getInstance();
            calendar_ST.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
                    calendar_as.get(Calendar.DATE) - 1, 0, 0, 0);
            calendar_ST.set(Calendar.MILLISECOND, 0);

            Calendar calendar_ET = Calendar.getInstance();
            calendar_ET.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
                    calendar_as.get(Calendar.DATE), 0, 0, 0);
            calendar_ET.set(Calendar.MILLISECOND, 0);

            SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");

            params.put("_startDate", dft.format(calendar_ST.getTime()));
            params.put("_endDate", dft.format(calendar_ET.getTime()));
            List<Order> orderList = orderService.selectAllOrders(params);

            for (int i = 0; i < orderList.size(); i++) {
                Order order = orderList.get(i);

                ws.addCell(new Label(0, i + 0, order.getOrderno(), wcf));
                ws.addCell(new Label(1, i + 0, order.getOrderno(), wcf));
                ws.addCell(new Label(2, i + 0, order.getPlatenumber(), wcf));
                ws.addCell(new Label(3, i + 0, " ", wcf));
                ws.addCell(new Label(4, i + 0, " ", wcf));
                ws.addCell(new Label(5, i + 0, " ", wcf));
                ws.addCell(new Label(6, i + 0, " ", wcf));
                ws.addCell(new Label(7, i + 0, " ", wcf));
                ws.addCell(new Label(8, i + 0, order.getChargingstartdate()==null?"":sdf.format(order.getChargingstartdate()), wcf));
                ws.addCell(new Label(9, i + 0,
                        order.getReturnvehicledate() == null ? " " :sdf.format(order.getReturnvehicledate()), wcf));
                ws.addCell(new Label(10, i + 0, " ", wcf));
                ws.addCell(new Label(11, i + 0, " ", wcf));
                ws.addCell(new Label(12, i + 0, order.getMileage() == null ? "0" : order.getMileage().toString(), wcf));
                ws.addCell(new Label(13, i + 0,
                        order.getActualpaymentcost() == null ? "0" : order.getActualpaymentcost().toString(), wcf));
            }

            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
            String lsize = String.valueOf(f.length());
            f.delete();
            ExcelMethod5New(lsize);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (RowsExceededException e) {
            e.printStackTrace();
        } catch (WriteException e) {
            e.printStackTrace();
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }
    private void ExcelMethod5New(String lsize){
        WritableWorkbook wwb;
        FileOutputStream fos;

        String savePath = ConfigUtil.pro.get("excelPath").toString();
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newDate = dateFormat.format(date);
        File f = new File(savePath);
        f = new File(f, "COL_WAY_"+newDate+"_"+lsize+"" + ".csv");

        try {

            fos = new FileOutputStream(f);
            wwb = Workbook.createWorkbook(fos);

            WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
                    UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            WritableCellFormat wcf = new WritableCellFormat(wf);
            wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
            wcf.setAlignment(Alignment.CENTRE);
            jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 设置数字格式
            jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 设置格式

            WritableSheet ws = wwb.createSheet("租赁结算单", 0); // 创建一个工作表
            ws.setRowView(1, 500);

            /// 租赁门店信息////////////////////////////////////////////////////////////////
            Map<String, Object> params = new HashMap<String, Object>();

            Calendar calendar_as = Calendar.getInstance();
            calendar_as.setTime(new Date());

            Calendar calendar_ST = Calendar.getInstance();
            calendar_ST.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
                    calendar_as.get(Calendar.DATE) - 1, 0, 0, 0);
            calendar_ST.set(Calendar.MILLISECOND, 0);

            Calendar calendar_ET = Calendar.getInstance();
            calendar_ET.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
                    calendar_as.get(Calendar.DATE), 0, 0, 0);
            calendar_ET.set(Calendar.MILLISECOND, 0);

            SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");

            params.put("_startDate", dft.format(calendar_ST.getTime()));
            params.put("_endDate", dft.format(calendar_ET.getTime()));
            List<Order> orderList = orderService.selectAllOrders(params);

            for (int i = 0; i < orderList.size(); i++) {
                Order order = orderList.get(i);

                ws.addCell(new Label(0, i + 0, order.getOrderno(), wcf));
                ws.addCell(new Label(1, i + 0, order.getOrderno(), wcf));
                ws.addCell(new Label(2, i + 0, order.getPlatenumber(), wcf));
                ws.addCell(new Label(3, i + 0, " ", wcf));
                ws.addCell(new Label(4, i + 0, " ", wcf));
                ws.addCell(new Label(5, i + 0, " ", wcf));
                ws.addCell(new Label(6, i + 0, " ", wcf));
                ws.addCell(new Label(7, i + 0, " ", wcf));
                ws.addCell(new Label(8, i + 0, order.getChargingstartdate()==null?"":sdf.format(order.getChargingstartdate()), wcf));
                ws.addCell(new Label(9, i + 0,
                        order.getReturnvehicledate() == null ? " " : sdf.format(order.getReturnvehicledate()), wcf));
                ws.addCell(new Label(10, i + 0, " ", wcf));
                ws.addCell(new Label(11, i + 0, " ", wcf));
                ws.addCell(new Label(12, i + 0, order.getMileage() == null ? "0" : order.getMileage().toString(), wcf));
                ws.addCell(new Label(13, i + 0,
                        order.getActualpaymentcost() == null ? "0" : order.getActualpaymentcost().toString(), wcf));
            }
            ////////////////////////////////////////////////////////////////////////////

            wwb.write();
            wwb.close();
            fos.flush();
            if(fos!=null){
                fos.close();
            }
        } catch (IOException e) {
        } catch (RowsExceededException e) {
        } catch (WriteException e) {
        }

        ///添加压缩功能/////////////////////////////////////////////////////////////////////
        String zipName = "COL_WAY_"+newDate+"_"+lsize+".zip";
        File fZ = new File(savePath);
        fZ = new File(fZ, zipName);
        ZipUtil zip =new ZipUtil();
        try {
            zip.zip(fZ.getPath(), f.getPath());
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        //新压缩包名称
        String zipNameNew = "COL_WAY_"+newDate+"_"+fZ.length()+".zip";
        File fZNew = new File(savePath);
        fZNew = new File(fZNew, zipNameNew);
        fileupload(fZ.getPath(),fZNew.getPath());
        // 调用sftp开始上传文件//////////////////////////////////////////////////////////////
        VehicleController vehicleController = new VehicleController();
        SftpUtil channel = vehicleController.getSFTPChannel();
        try {
            ChannelSftp chSftp = channel.getChannel(60000);
            String strSaveUrl = "/COLLECTION/" + fZ.getName();
            chSftp.put(fZ.getPath(), strSaveUrl, ChannelSftp.OVERWRITE);
            chSftp.quit();
            channel.closeChannel();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    /**
     * 获取文件大小 重新写入磁盘
     * @author:cuijinlong
     * @date:2017年5月18日 下午1:58:37
     * @param url1
     * @param url2
     */
    private void fileupload(String url1,String url2){
         File f = new File(url1);//旧文件路径
         InputStream in = null;
         FileOutputStream out = null;
        try {
             in = new FileInputStream(f);//输入流把旧文件写到流里面
             int tempbyte;
             System.out.println(in.available());
             byte[]  b = new byte[in.available()];
             while ((tempbyte = in.read(b, 0,b.length)) != -1) {
                 System.out.write(tempbyte);/写入文件内容
             }
             File f2 = new File(url2);/新文件路径

             out = new FileOutputStream(f2);
             out.write(b);
             out.flush();
             f.delete();/删除旧文件
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            try {
                if(in != null){
                    in.close();
                }
                if(out != null){
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }

}
时间: 2024-10-08 06:53:58

导出EXCEL上传 服务器 添加压缩包,获取文件 大小的相关文章

C# FTP 上传、下载、获取文件列表

static public class FtpHelper { //基本设置 static private string path = @"ftp://" + Helper.GetAppConfig("obj") + "/"; //目标路径 static private string ftpip =Helper.GetAppConfig("obj"); //ftp IP地址 static private string user

关于使用SVN上传、添加、删除文件

操作步骤 1. 本地建立仓库:在本地新建文件夹,右键 -> TortoiseSVN -> Create repository here: 2. 下载已有仓库:在本地新建文件夹,右键 -> Checkout -> 输入用户名密码.下载的文件路径: 3. 更新本地仓库:选中仓库,右键 -> SVN Update: 4. 上传本地文件:选中仓库,右键 -> SVN Commit: 5. 添加文件:选中文件,右键 -> TortoiseSVN -> add:出现加号

解决&lt;s:file&gt;上传文件大小和 不能获取文件问题

1.<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.200000762939453px;">表单标签中设置enctype="multipart/form-data"来确保匿名上载文件的正确编码.</span> <s:form action="part_add.action"

ajaxFileUpload+struts2实现多文件上传(动态添加文件上传框)

上篇文章http://blog.csdn.net/itmyhome1990/article/details/36396291介绍了ajaxfileupload实现多文件上传, 但只是固定的文件个数,如果需求不确定是多少文件 则我们就需要动态的添加文件上传框,以实现灵活性. 基于上篇基本框架是不变的,主要修改以下几个方面 1.jQuery实现动态添加删除文件上传框 2.获取文件上传框的ID 3.ajaxfileupload.js里将ID数组转换为需要的Object数组 依次解决上面问题 一.实现动

ASP.NET MVC编程入门--Excel上传

参考博客:ASP.NET MVC下使用文件上传 参考博客:NPOI使用手册 参考博客:ASP.Net MVC利用NPOI导入导出Excel 参考博客:C# NPOI 导入与导出Excel文档 兼容xlsx, xls 文件上传代码块 #region EXCEL上传 /// <summary> /// EXCEL上传 /// </summary> /// <param name="fileData"></param> /// <retu

IT轮子系列(六)——Excel上传与解析,一套代码解决所有Excel业务上传,你Get到了吗

前言 在日常开发当中,excel的上传与解析是很常见的.根据业务不同,解析的数据模型也都不一样.不同的数据模型也就需要不同的校验逻辑,这往往需要写多套的代码进行字段的检验,如必填项,数据格式.为了避免重复编写逻辑检验代码,于是有了这篇文章. 第一步.读取Excel表格数据 1 public ActionResult UploadExcel() 2 { 3 ResultInfo<List<User>> result = new ResultInfo<List<User&g

java多线程文件上传服务器

描述: (1)jdk自带线程池见 JDK自带线程池配置 (2)此上传文件服务器中上传文件的后缀名通过第一段缓冲字符流传递,此缓冲字符流大小为1024,在文件接收端以1024接收.处理. 1.服务器代码如下(使用jdk自带线程池): 1 /** 2 * 服务器处理多线程问题 3 * 4 * 1.因为服务器是要很多人访问的,因此里面一定要用多线程来处理,不然只能一个人一个人的访问,那还叫Y啥服务器 5 * 6 * 2,拿上面这个文件上传的例子来说,它将每个连接它的用户封装到线程里面去,把用户要执行的

Excel上传并读取数据

最近一段时间,维护一个旧系统,其中有一个功能,是把Excel上传,并读取数据进行维护,然后转插入至SQL数据库中.下面Insus.NET使用asp.net 标准上传控件: <asp:FileUpload ID="FileUpload1" runat="server" /> Insus.NET习惯性,在每一个专案中,都会创建一个临时目录. 因为很多时候,我们处理一些临时文件,或是数据均可在此临时目录中进行.它有点像Windows下的临时目录一样. 上面代码

C#Excel上传批量导入sqlserver

前台: <x:FileUpload ID="btnUpField" runat="server" Label="上传Excel批量导入用户信息" ShowLabel="true" > </x:FileUpload> <x:Button ID="Button1" Text="上传" runat="server" Icon="Sys