package com.pqs9000.util;

import com.njcn.enums.DicDataTypeEnum;
import com.pqs9000.controller.responsibility.ResponsibilityListController;
import com.pqs9000.pojo.responsibility.AreaOverNoraml;
import com.pqs9000.pojo.responsibility.OverLimitMonitor;
import com.pqs9000.pojo.responsibility.WarningSubstation;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;

/**
 * @author xuyang
 * @date 2020/9/29 10:48
 * 区域稳态指标超标 excel模板
 */

public class ComplexHeadExcel{

    private static final Logger logger = LoggerFactory.getLogger(ResponsibilityListController.class);

    private XSSFWorkbook xssfWorkbook;


    /**
     * 区域稳态指标超标报表
     */
    public void exportAreaReport(HttpServletResponse response, HttpServletRequest request, List<AreaOverNoraml> list,String startTime,String endTime,String statistic){
        String type = getType(statistic);
        xssfWorkbook = new XSSFWorkbook();
        XSSFSheet xssfSheet = xssfWorkbook.createSheet("sheet");
        String fileName = "区域稳态指标超标报表_"+startTime+"-"+endTime+"_"+type;
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XSSFRow row = xssfSheet.createRow(0);
        XSSFRow row2 = xssfSheet.createRow(1);
        XSSFCell cell = null;
        InputStream is = null;

        //合并
        CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
        xssfSheet.addMergedRegion(region);
        CellRangeAddress region1 = new CellRangeAddress(0, 1, 1, 1);
        xssfSheet.addMergedRegion(region1);
        CellRangeAddress region2 = new CellRangeAddress(0, 1, 2, 2);
        xssfSheet.addMergedRegion(region2);
        CellRangeAddress region3 = new CellRangeAddress(0, 1, 3, 3);
        xssfSheet.addMergedRegion(region3);
        CellRangeAddress region4 = new CellRangeAddress(0, 1, 4, 4);
        xssfSheet.addMergedRegion(region4);
        CellRangeAddress region5 = new CellRangeAddress(0, 0, 5, 8);
        xssfSheet.addMergedRegion(region5);
        CellRangeAddress region6 = new CellRangeAddress(0, 0, 9, 12);
        xssfSheet.addMergedRegion(region6);
        CellRangeAddress region7 = new CellRangeAddress(0, 0, 13, 16);
        xssfSheet.addMergedRegion(region7);
        CellRangeAddress region8 = new CellRangeAddress(0, 0, 17, 20);
        xssfSheet.addMergedRegion(region8);
        CellRangeAddress region9 = new CellRangeAddress(0, 0, 21, 24);
        xssfSheet.addMergedRegion(region9);
        CellRangeAddress region10 = new CellRangeAddress(0, 0, 25, 28);
        xssfSheet.addMergedRegion(region10);
        CellRangeAddress region11 = new CellRangeAddress(0, 0, 29, 32);
        xssfSheet.addMergedRegion(region11);
        CellRangeAddress region12 = new CellRangeAddress(0, 0, 33, 36);
        xssfSheet.addMergedRegion(region12);


        //设置单元格大小
        xssfSheet.setColumnWidth(0, 2000);
        xssfSheet.setColumnWidth(1, 4000);
        xssfSheet.setColumnWidth(2, 5000);
        xssfSheet.setColumnWidth(3, 5000);
        xssfSheet.setColumnWidth(4, 5000);

        xssfSheet.setColumnWidth(5, 3500);
        xssfSheet.setColumnWidth(6, 3500);
        xssfSheet.setColumnWidth(7, 3500);
        xssfSheet.setColumnWidth(8, 5500);

        xssfSheet.setColumnWidth(9, 3500);
        xssfSheet.setColumnWidth(10, 3500);
        xssfSheet.setColumnWidth(11, 3500);
        xssfSheet.setColumnWidth(12, 5500);

        xssfSheet.setColumnWidth(13, 3500);
        xssfSheet.setColumnWidth(14, 3500);
        xssfSheet.setColumnWidth(15, 3500);
        xssfSheet.setColumnWidth(16, 5500);

        xssfSheet.setColumnWidth(17, 3500);
        xssfSheet.setColumnWidth(18, 3500);
        xssfSheet.setColumnWidth(19, 3500);
        xssfSheet.setColumnWidth(20, 5500);

        xssfSheet.setColumnWidth(21, 3500);
        xssfSheet.setColumnWidth(22, 3500);
        xssfSheet.setColumnWidth(23, 3500);
        xssfSheet.setColumnWidth(24, 5500);

        xssfSheet.setColumnWidth(25, 3500);
        xssfSheet.setColumnWidth(26, 3500);
        xssfSheet.setColumnWidth(27, 3500);
        xssfSheet.setColumnWidth(28, 5500);

        xssfSheet.setColumnWidth(29, 3500);
        xssfSheet.setColumnWidth(30, 3500);
        xssfSheet.setColumnWidth(31, 3500);
        xssfSheet.setColumnWidth(32, 5500);

        xssfSheet.setColumnWidth(33, 3500);
        xssfSheet.setColumnWidth(34, 3500);
        xssfSheet.setColumnWidth(35, 3500);
        xssfSheet.setColumnWidth(36, 5500);

        //一级表头
        cell = row.createCell(0);
        cell.setCellValue("序号");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(1);
        cell.setCellValue("单位");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(2);
        cell.setCellValue("在线监测点数量(个)");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(3);
        cell.setCellValue("超标监测点数量(个)");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(4);
        cell.setCellValue("超标监测点占比(%)");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(5);
        cell.setCellValue("频率偏差超标情况");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(9);
        cell.setCellValue("电压偏差超标情况");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(13);
        cell.setCellValue("谐波电压超标情况");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(17);
        cell.setCellValue("谐波电流超标情况");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(21);
        cell.setCellValue("三相电压不平衡度超标情况");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(25);
        cell.setCellValue("闪变超标情况");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(29);
        cell.setCellValue("负序电流超标情况");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(33);
        cell.setCellValue("间谐波电压超标情况");
        cell.setCellStyle(getStyle(1));

        //二级表头
        cell = row2.createCell(5);
        cell.setCellValue("超标个数(个)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(6);
        cell.setCellValue("累计占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(7);
        cell.setCellValue("日均占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(8);
        cell.setCellValue("平均超标天数(天/点)");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(9);
        cell.setCellValue("超标个数(个)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(10);
        cell.setCellValue("累计占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(11);
        cell.setCellValue("日均占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(12);
        cell.setCellValue("平均超标天数(天/点)");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(13);
        cell.setCellValue("超标个数(个)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(14);
        cell.setCellValue("累计占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(15);
        cell.setCellValue("日均占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(16);
        cell.setCellValue("平均超标天数(天/点)");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(17);
        cell.setCellValue("超标个数(个)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(18);
        cell.setCellValue("累计占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(19);
        cell.setCellValue("日均占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(20);
        cell.setCellValue("平均超标天数(天/点)");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(21);
        cell.setCellValue("超标个数(个)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(22);
        cell.setCellValue("累计占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(23);
        cell.setCellValue("日均占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(24);
        cell.setCellValue("平均超标天数(天/点)");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(25);
        cell.setCellValue("超标个数(个)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(26);
        cell.setCellValue("累计占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(27);
        cell.setCellValue("日均占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(28);
        cell.setCellValue("平均超标天数(天/点)");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(29);
        cell.setCellValue("超标个数(个)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(30);
        cell.setCellValue("累计占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(31);
        cell.setCellValue("日均占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(32);
        cell.setCellValue("平均超标天数(天/点)");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(33);
        cell.setCellValue("超标个数(个)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(34);
        cell.setCellValue("累计占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(35);
        cell.setCellValue("日均占比(%)");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(36);
        cell.setCellValue("平均超标天数(天/点)");
        cell.setCellStyle(getStyle(1));

        //写入数据
        try {
            for (int i=0;i<list.size();i++){
                os = new ByteArrayOutputStream();
                row =  xssfSheet.createRow(i+2);

                cell = row.createCell(0);
                cell.setCellValue(i+1);

                cell = row.createCell(1);
                cell.setCellValue(list.get(i).getName());

                cell = row.createCell(2);
                cell.setCellValue(list.get(i).getOnlineMonitorNumber());

                cell = row.createCell(3);
                cell.setCellValue(list.get(i).getOverLimitMonitorNumber());

                cell = row.createCell(4);
                cell.setCellValue(list.get(i).getOverBiLi());

                cell = row.createCell(5);
                cell.setCellValue(list.get(i).getFrequencyMonitorNumber());

                cell = row.createCell(6);
                cell.setCellValue(list.get(i).getFrequencyBiLi());

                cell = row.createCell(7);
                cell.setCellValue(list.get(i).getFrequencyAvg());

                cell = row.createCell(8);
                cell.setCellValue(list.get(i).getFrequencyOverDayBiLi());

                cell = row.createCell(9);
                cell.setCellValue(list.get(i).getVoltageMonitorNumber());

                cell = row.createCell(10);
                cell.setCellValue(list.get(i).getVoltageBiLi());

                cell = row.createCell(11);
                cell.setCellValue(list.get(i).getVoltageAvg());

                cell = row.createCell(12);
                cell.setCellValue(list.get(i).getVoltageOverDayBiLi());

                cell = row.createCell(13);
                cell.setCellValue(list.get(i).getHarmonicVoltageMonitorNumber());

                cell = row.createCell(14);
                cell.setCellValue(list.get(i).getHarmonicVoltageBiLi());

                cell = row.createCell(15);
                cell.setCellValue(list.get(i).getHarmonicVoltageAvg());

                cell = row.createCell(16);
                cell.setCellValue(list.get(i).getHarmonicVoltageOverDayBiLi());

                cell = row.createCell(17);
                cell.setCellValue(list.get(i).getHarmonicCurrentMonitorNumber());

                cell = row.createCell(18);
                cell.setCellValue(list.get(i).getHarmonicCurrentBiLi());

                cell = row.createCell(19);
                cell.setCellValue(list.get(i).getHarmonicCurrentAvg());

                cell = row.createCell(20);
                cell.setCellValue(list.get(i).getHarmonicCurrentOverDayBiLi());

                cell = row.createCell(21);
                cell.setCellValue(list.get(i).getThreePhaseVoltageMonitorNumber());

                cell = row.createCell(22);
                cell.setCellValue(list.get(i).getThreePhaseVoltageBiLi());

                cell = row.createCell(23);
                cell.setCellValue(list.get(i).getThreePhaseVoltageAvg());

                cell = row.createCell(24);
                cell.setCellValue(list.get(i).getThreePhaseVoltageOverDayBiLi());

                cell = row.createCell(25);
                cell.setCellValue(list.get(i).getFlickerMonitorNumber());

                cell = row.createCell(26);
                cell.setCellValue(list.get(i).getFlickerBiLi());

                cell = row.createCell(27);
                cell.setCellValue(list.get(i).getFlickerAvg());

                cell = row.createCell(28);
                cell.setCellValue(list.get(i).getFlickerOverDayBiLi());

                cell = row.createCell(29);
                cell.setCellValue(list.get(i).getNegativeMonitorNumber());

                cell = row.createCell(30);
                cell.setCellValue(list.get(i).getNegativeBiLi());

                cell = row.createCell(31);
                cell.setCellValue(list.get(i).getNegativeAvg());

                cell = row.createCell(32);
                cell.setCellValue(list.get(i).getNegativeOverDayBiLi());

                cell = row.createCell(33);
                cell.setCellValue(list.get(i).getInterharmonicMonitorNumber());

                cell = row.createCell(34);
                cell.setCellValue(list.get(i).getInterharmonicBiLi());

                cell = row.createCell(35);
                cell.setCellValue(list.get(i).getInterharmonicAvg());

                cell = row.createCell(36);
                cell.setCellValue(list.get(i).getInterharmonicOverDayBiLi());

                xssfWorkbook.write(os);
            }
            //设置response参数，可以打开下载界面
            response.reset();
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xlsx").getBytes(), "iso-8859-1"));
            ServletOutputStream out = response.getOutputStream();
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            byte[] content = os.toByteArray();
            is = new ByteArrayInputStream(content);
            bis = new BufferedInputStream(is);
            bos = new BufferedOutputStream(out);
            byte[] buff = new byte[2048];
            int bytesRead;
            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
            bis.close();
            bos.close();
        } catch (IOException e) {
            logger.error("异常为："+e.toString());
        }
    }

    //获取统计类型
    public String getType(String statistic){
        String type = "";
        switch (statistic) {
            case "0":
                type = "电网拓扑";
                break;
            case "1":
                type = DicDataTypeEnum.payloadEnum.getName();
                break;
            case "2":
                type = "电压等级";
                break;
            default:
                break;
        }
        return type;
    }

    /**
     * 告警变电站明细
     */
    public void exportSubReport(HttpServletResponse response, HttpServletRequest request, List<WarningSubstation> list,String startTime,String endTime){
        xssfWorkbook = new XSSFWorkbook();
        XSSFSheet xssfSheet = xssfWorkbook.createSheet("sheet");
        String fileName = "告警变电站明细报表_"+startTime+"-"+endTime;
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XSSFRow row = xssfSheet.createRow(0);
        XSSFRow row2 = xssfSheet.createRow(1);
        XSSFCell cell = null;
        InputStream is = null;

        //合并
        CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
        xssfSheet.addMergedRegion(region);
        CellRangeAddress region1 = new CellRangeAddress(0, 1, 1, 1);
        xssfSheet.addMergedRegion(region1);
        CellRangeAddress region2 = new CellRangeAddress(0, 1, 2, 2);
        xssfSheet.addMergedRegion(region2);
        CellRangeAddress region3 = new CellRangeAddress(0, 1, 3, 3);
        xssfSheet.addMergedRegion(region3);
        CellRangeAddress region4 = new CellRangeAddress(0, 1, 4, 4);
        xssfSheet.addMergedRegion(region4);
        CellRangeAddress region5 = new CellRangeAddress(0, 1, 5, 5);
        xssfSheet.addMergedRegion(region5);
        CellRangeAddress region6 = new CellRangeAddress(0, 1, 6, 6);
        xssfSheet.addMergedRegion(region6);
        CellRangeAddress region7 = new CellRangeAddress(0, 1, 7, 7);
        xssfSheet.addMergedRegion(region7);
//        CellRangeAddress region8 = new CellRangeAddress(0, 1, 8, 8);
//        xssfSheet.addMergedRegion(region8);
        CellRangeAddress region9 = new CellRangeAddress(0, 0, 8, 15);
        xssfSheet.addMergedRegion(region9);
        CellRangeAddress region10 = new CellRangeAddress(0, 0, 16, 18);
        xssfSheet.addMergedRegion(region10);

        //设置单元格大小
        xssfSheet.setColumnWidth(0, 2000);
//        xssfSheet.setColumnWidth(1, 4000);
        xssfSheet.setColumnWidth(1, 4000);
        xssfSheet.setColumnWidth(2, 5000);
        xssfSheet.setColumnWidth(3, 5000);
        xssfSheet.setColumnWidth(4, 5000);
        xssfSheet.setColumnWidth(5, 6500);
        xssfSheet.setColumnWidth(6, 5000);
        xssfSheet.setColumnWidth(7, 4000);
        xssfSheet.setColumnWidth(8, 5000);
        xssfSheet.setColumnWidth(9, 5000);
        xssfSheet.setColumnWidth(10, 5000);
        xssfSheet.setColumnWidth(11, 5000);
        xssfSheet.setColumnWidth(12, 5000);
        xssfSheet.setColumnWidth(13, 5000);
        xssfSheet.setColumnWidth(14, 5000);
        xssfSheet.setColumnWidth(15, 5000);
        xssfSheet.setColumnWidth(16, 5000);
        xssfSheet.setColumnWidth(17, 5000);
        xssfSheet.setColumnWidth(18, 5000);



        //一级表头
        cell = row.createCell(0);
        cell.setCellValue("序号");
        cell.setCellStyle(getStyle(1));
        cell = row.createCell(1);
//        cell.setCellValue("省公司");
//        cell.setCellStyle(getStyle(1));
//        cell = row.createCell(2);
        cell.setCellValue("地市公司");
        cell.setCellStyle(getStyle(1));
        cell = row.createCell(2);
        cell.setCellValue("电站名称");
        cell.setCellStyle(getStyle(1));
        cell = row.createCell(3);
        cell.setCellValue("电站电压等级");
        cell.setCellStyle(getStyle(1));
        cell = row.createCell(4);
        cell.setCellValue("在线监测点数量(个)");
        cell.setCellStyle(getStyle(1));
        cell = row.createCell(5);
        cell.setCellValue("告警监测点数量(个)");
        cell.setCellStyle(getStyle(1));
        cell = row.createCell(6);
        cell.setCellValue("告警次数");
        cell.setCellStyle(getStyle(1));
        cell = row.createCell(7);
        cell.setCellValue("告警频次(次/点)");
        cell.setCellStyle(getStyle(1));
        cell = row.createCell(8);
        cell.setCellValue("各项稳态指标告警频次(次/点)");
        cell.setCellStyle(getStyle(1));
        cell = row.createCell(9);
        cell.setCellValue("各项暂态指标告警频次(次/点)");
        cell.setCellStyle(getStyle(1));


        //二级表头电压总谐波畸变率
        cell = row2.createCell(8);
        cell.setCellValue("频率偏差");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(9);
        cell.setCellValue("电压偏差");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(10);
        cell.setCellValue("谐波电压");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(11);
        cell.setCellValue("谐波电流");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(12);
        cell.setCellValue("三相电压不平衡度");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(13);
        cell.setCellValue("闪变");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(14);
        cell.setCellValue("间谐波电压");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(15);
        cell.setCellValue("负序电流");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(16);
        cell.setCellValue("短时中断");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(17);
        cell.setCellValue("电压暂降");
        cell.setCellStyle(getStyle(1));
        cell = row2.createCell(18);
        cell.setCellValue("电压暂升");
        cell.setCellStyle(getStyle(1));


        try{
            for (int i=0;i<list.size();i++){
                os = new ByteArrayOutputStream();
                row =  xssfSheet.createRow(i+2);

                cell = row.createCell(0);
                cell.setCellValue(i+1);

//                cell = row.createCell(1);
//                cell.setCellValue(list.get(i).getProvinceCompany());

                cell = row.createCell(1);
                cell.setCellValue(list.get(i).getCityCompany());

                cell = row.createCell(2);
                cell.setCellValue(list.get(i).getPlantName());

                cell = row.createCell(3);
                cell.setCellValue(list.get(i).getPlantVoltageLevel());

                cell = row.createCell(4);
                cell.setCellValue(list.get(i).getOnlineMonitorCounts());

                cell = row.createCell(5);
                cell.setCellValue(list.get(i).getAlertMonitorCounts());

                cell = row.createCell(6);
                cell.setCellValue(list.get(i).getAlertCounts());

                cell = row.createCell(7);
                cell.setCellValue(list.get(i).getAlertAlarmFrequency());

                cell = row.createCell(8);
                cell.setCellValue(list.get(i).getFrequencyDeviation());

                cell = row.createCell(9);
                cell.setCellValue(list.get(i).getVoltageDeviation());

                cell = row.createCell(10);
                cell.setCellValue(list.get(i).getHarmonicVoltage());

                cell = row.createCell(11);
                cell.setCellValue(list.get(i).getHarmonicCurrent());

                cell = row.createCell(12);
                cell.setCellValue(list.get(i).getThreePhaseVoltageUnbalance());

                cell = row.createCell(13);
                cell.setCellValue(list.get(i).getFlicker());

                cell = row.createCell(14);
                cell.setCellValue(list.get(i).getInterharmonic());

                cell = row.createCell(15);
                cell.setCellValue(list.get(i).getNegative());

                cell = row.createCell(16);
                cell.setCellValue(list.get(i).getShortInterruption());

                cell = row.createCell(17);
                cell.setCellValue(list.get(i).getVoltageDip());

                cell = row.createCell(18);
                cell.setCellValue(list.get(i).getVoltageSwell());

                xssfWorkbook.write(os);
            }

            //设置response参数，可以打开下载界面
            response.reset();
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xlsx").getBytes(), "iso-8859-1"));
            ServletOutputStream out = response.getOutputStream();
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            byte[] content = os.toByteArray();
            is = new ByteArrayInputStream(content);
            bis = new BufferedInputStream(is);
            bos = new BufferedOutputStream(out);
            byte[] buff = new byte[2048];
            int bytesRead;
            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
            bis.close();
            bos.close();
        } catch (IOException e) {
            logger.error("异常为："+e.toString());
        }
    }




    /**
     * 监测点稳态超标
     */
    public void exportMonitorReport(HttpServletResponse response, HttpServletRequest request, List<OverLimitMonitor> list,String startTime,String endTime){
        xssfWorkbook = new XSSFWorkbook();
        XSSFSheet xssfSheet = xssfWorkbook.createSheet("sheet");
        String fileName = "监测点稳态超标报表_"+startTime+"-"+endTime;
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XSSFRow row = xssfSheet.createRow(0);
        XSSFRow row2 = xssfSheet.createRow(1);
        XSSFRow row3 = xssfSheet.createRow(2);
        XSSFCell cell = null;
        InputStream is = null;

        //合并
        CellRangeAddress region = new CellRangeAddress(0, 2, 0, 0);
        xssfSheet.addMergedRegion(region);
        CellRangeAddress region1 = new CellRangeAddress(0, 2, 1, 1);
        xssfSheet.addMergedRegion(region1);
        CellRangeAddress region2 = new CellRangeAddress(0, 2, 2, 2);
        xssfSheet.addMergedRegion(region2);
        CellRangeAddress region3 = new CellRangeAddress(0, 2, 3, 3);
        xssfSheet.addMergedRegion(region3);
        CellRangeAddress region4 = new CellRangeAddress(0, 2, 4, 4);
        xssfSheet.addMergedRegion(region4);
        CellRangeAddress region5 = new CellRangeAddress(0, 2, 5, 5);
        xssfSheet.addMergedRegion(region5);
        CellRangeAddress region6 = new CellRangeAddress(0, 2, 6, 6);
        xssfSheet.addMergedRegion(region6);
        CellRangeAddress region7 = new CellRangeAddress(0, 2, 7, 7);
        xssfSheet.addMergedRegion(region7);
        CellRangeAddress region8 = new CellRangeAddress(0, 2, 8, 8);
        xssfSheet.addMergedRegion(region8);
        CellRangeAddress region9 = new CellRangeAddress(0, 2, 9, 9);
        xssfSheet.addMergedRegion(region9);
        CellRangeAddress region10 = new CellRangeAddress(0, 2, 10, 10);
        xssfSheet.addMergedRegion(region10);
        CellRangeAddress region11 = new CellRangeAddress(0, 2, 11, 11);
        xssfSheet.addMergedRegion(region11);
        CellRangeAddress region12 = new CellRangeAddress(0, 2, 12, 12);
        xssfSheet.addMergedRegion(region12);
        CellRangeAddress region13 = new CellRangeAddress(0, 2, 13, 13);
        xssfSheet.addMergedRegion(region13);
        CellRangeAddress region14 = new CellRangeAddress(0, 0, 14, 70);
        xssfSheet.addMergedRegion(region14);
        //电压变差
        CellRangeAddress region15 = new CellRangeAddress(1, 1, 14, 17);
        xssfSheet.addMergedRegion(region15);
        //谐波电流
        CellRangeAddress region16 = new CellRangeAddress(1, 1, 18, 21);
        xssfSheet.addMergedRegion(region16);
        //谐波电压
        CellRangeAddress region17 = new CellRangeAddress(1, 1, 22, 25);
        xssfSheet.addMergedRegion(region17);
        //电压总谐波畸变率
        CellRangeAddress region18 = new CellRangeAddress(1, 1, 26, 29);
        xssfSheet.addMergedRegion(region18);
        //谐波电压含有率
        CellRangeAddress region19 = new CellRangeAddress(1, 1, 30, 33);
        xssfSheet.addMergedRegion(region19);
        //三相电压不平衡度
        CellRangeAddress region20 = new CellRangeAddress(1, 1, 34, 37);
        xssfSheet.addMergedRegion(region20);
        //频率偏差
        CellRangeAddress region21 = new CellRangeAddress(1, 1, 38, 41);
        xssfSheet.addMergedRegion(region21);
        //间谐波电压含有率
        CellRangeAddress region22 = new CellRangeAddress(1, 1, 42, 45);
        xssfSheet.addMergedRegion(region22);
        //负序电流
        CellRangeAddress region23 = new CellRangeAddress(1, 1, 46, 49);
        xssfSheet.addMergedRegion(region23);
        //闪变
        CellRangeAddress region24 = new CellRangeAddress(1, 1, 50, 53);
        xssfSheet.addMergedRegion(region24);
        //各次谐波电压含有率超标天数
        CellRangeAddress region25 = new CellRangeAddress(1, 1, 54, 61);
        xssfSheet.addMergedRegion(region25);
        //各次谐波电流幅值超标天数
        CellRangeAddress region26 = new CellRangeAddress(1, 1, 62, 69);
        xssfSheet.addMergedRegion(region26);
        //监测点编号
        CellRangeAddress region27 = new CellRangeAddress(1, 2, 70, 70);
        xssfSheet.addMergedRegion(region27);

        //设置单元格大小
        xssfSheet.setColumnWidth(0, 2000);
        xssfSheet.setColumnWidth(1, 4000);
        xssfSheet.setColumnWidth(2, 4000);
        xssfSheet.setColumnWidth(3, 5000);
        xssfSheet.setColumnWidth(4, 5000);
        xssfSheet.setColumnWidth(5, 5000);
        xssfSheet.setColumnWidth(6, 5000);
        xssfSheet.setColumnWidth(7, 4000);
        xssfSheet.setColumnWidth(8, 5000);
        xssfSheet.setColumnWidth(9, 4000);
        xssfSheet.setColumnWidth(10, 4000);
        xssfSheet.setColumnWidth(11, 4000);
        xssfSheet.setColumnWidth(12, 4000);
        xssfSheet.setColumnWidth(13, 4000);
        xssfSheet.setColumnWidth(14, 5000);
        xssfSheet.setColumnWidth(15, 5000);
        xssfSheet.setColumnWidth(16, 2500);
        xssfSheet.setColumnWidth(17, 2500);
        xssfSheet.setColumnWidth(18, 2500);
        xssfSheet.setColumnWidth(19, 2500);
        xssfSheet.setColumnWidth(20, 2500);
        xssfSheet.setColumnWidth(21, 2500);
        xssfSheet.setColumnWidth(22, 2500);
        xssfSheet.setColumnWidth(23, 2500);
        xssfSheet.setColumnWidth(24, 2500);
        xssfSheet.setColumnWidth(25, 2500);
        xssfSheet.setColumnWidth(26, 2500);
        xssfSheet.setColumnWidth(27, 2500);
        xssfSheet.setColumnWidth(28, 2500);
        xssfSheet.setColumnWidth(29, 2500);
        xssfSheet.setColumnWidth(30, 2500);
        xssfSheet.setColumnWidth(31, 2500);
        xssfSheet.setColumnWidth(32, 2500);
        xssfSheet.setColumnWidth(33, 2500);
        xssfSheet.setColumnWidth(34, 2500);
        xssfSheet.setColumnWidth(35, 2500);
        xssfSheet.setColumnWidth(36, 2500);
        xssfSheet.setColumnWidth(37, 2500);
        xssfSheet.setColumnWidth(38, 2500);
        xssfSheet.setColumnWidth(39, 2500);
        xssfSheet.setColumnWidth(40, 2500);
        xssfSheet.setColumnWidth(41, 2500);
        xssfSheet.setColumnWidth(42, 2500);
        xssfSheet.setColumnWidth(43, 2500);
        xssfSheet.setColumnWidth(44, 2500);
        xssfSheet.setColumnWidth(45, 2500);
        xssfSheet.setColumnWidth(46, 2500);
        xssfSheet.setColumnWidth(47, 2500);
        xssfSheet.setColumnWidth(48, 2500);
        xssfSheet.setColumnWidth(49, 2500);
        xssfSheet.setColumnWidth(50, 2500);
        xssfSheet.setColumnWidth(51, 2500);
        xssfSheet.setColumnWidth(52, 2500);
        xssfSheet.setColumnWidth(53, 2500);
        xssfSheet.setColumnWidth(54, 2500);
        xssfSheet.setColumnWidth(55, 2500);
        xssfSheet.setColumnWidth(56, 2500);
        xssfSheet.setColumnWidth(57, 2500);
        xssfSheet.setColumnWidth(58, 2500);
        xssfSheet.setColumnWidth(59, 2500);
        xssfSheet.setColumnWidth(60, 2500);
        xssfSheet.setColumnWidth(61, 2500);
        xssfSheet.setColumnWidth(62, 2500);
        xssfSheet.setColumnWidth(63, 2500);
        xssfSheet.setColumnWidth(64, 2500);
        xssfSheet.setColumnWidth(65, 2500);
        xssfSheet.setColumnWidth(66, 2500);
        xssfSheet.setColumnWidth(67, 2500);
        xssfSheet.setColumnWidth(68, 2500);
        xssfSheet.setColumnWidth(69, 2500);
        xssfSheet.setColumnWidth(70, 2500);

        //一级表头
        cell = row.createCell(0);
        cell.setCellValue("序号");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(1);
        cell.setCellValue("省公司");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(2);
        cell.setCellValue("地市公司");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(3);
        cell.setCellValue("监测点名称");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(4);
        cell.setCellValue("干扰源类型");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(5);
        cell.setCellValue("电网侧变电站名称");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(6);
        cell.setCellValue("监测点对象名称");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(7);
        cell.setCellValue("监测点电压等级");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(8);
        cell.setCellValue("监测点所在变电站/场站名称");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(9);
        cell.setCellValue("监测点所在变电站/场站电压等级");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(10);
        cell.setCellValue("最小短路容量");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(11);
        cell.setCellValue("供电设备容量");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(12);
        cell.setCellValue("用户协议容量");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(13);
        cell.setCellValue("超标天数");
        cell.setCellStyle(getStyle(1));

        cell = row.createCell(14);
        cell.setCellValue("各项指标超标明细");
        cell.setCellStyle(getStyle(1));

        //二级表头
        cell = row2.createCell(14);
        cell.setCellValue("电压偏差");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(18);
        cell.setCellValue("谐波电流");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(22);
        cell.setCellValue("谐波电压");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(26);
        cell.setCellValue("电压总谐波畸变率");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(30);
        cell.setCellValue("谐波电压含有率");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(34);
        cell.setCellValue("三相电压不平衡度");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(38);
        cell.setCellValue("频率偏差");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(42);
        cell.setCellValue("间谐波电压含有率");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(46);
        cell.setCellValue("负序电流");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(50);
        cell.setCellValue("闪变");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(54);
        cell.setCellValue("各次谐波电压含有率");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(62);
        cell.setCellValue("各次谐波电流幅值");
        cell.setCellStyle(getStyle(1));

        cell = row2.createCell(70);
        cell.setCellValue("监测点编号");
        cell.setCellStyle(getStyle(1));

        //三级表头
        cell = row3.createCell(14);
        cell.setCellValue("超标天数");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(15);
        cell.setCellValue("最大幅值(绝对值)");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(16);
        cell.setCellValue("限值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(17);
        cell.setCellValue("差值");
        cell.setCellStyle(getStyle(1));

        cell = row3.createCell(18);
        cell.setCellValue("超标天数");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(19);
        cell.setCellValue("最大幅值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(20);
        cell.setCellValue("限值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(21);
        cell.setCellValue("差值");
        cell.setCellStyle(getStyle(1));

        cell = row3.createCell(22);
        cell.setCellValue("超标天数");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(23);
        cell.setCellValue("最大幅值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(24);
        cell.setCellValue("限值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(25);
        cell.setCellValue("差值");
        cell.setCellStyle(getStyle(1));

        cell = row3.createCell(26);
        cell.setCellValue("超标天数");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(27);
        cell.setCellValue("最大幅值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(28);
        cell.setCellValue("限值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(29);
        cell.setCellValue("差值");
        cell.setCellStyle(getStyle(1));

        cell = row3.createCell(30);
        cell.setCellValue("超标天数");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(31);
        cell.setCellValue("最大幅值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(32);
        cell.setCellValue("限值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(33);
        cell.setCellValue("差值");
        cell.setCellStyle(getStyle(1));

        cell = row3.createCell(34);
        cell.setCellValue("超标天数");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(35);
        cell.setCellValue("最大幅值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(36);
        cell.setCellValue("限值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(37);
        cell.setCellValue("差值");
        cell.setCellStyle(getStyle(1));

        cell = row3.createCell(38);
        cell.setCellValue("超标天数");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(39);
        cell.setCellValue("最大幅值(绝对值)");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(40);
        cell.setCellValue("限值(±)");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(41);
        cell.setCellValue("差值");
        cell.setCellStyle(getStyle(1));

        cell = row3.createCell(42);
        cell.setCellValue("超标天数");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(43);
        cell.setCellValue("最大幅值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(44);
        cell.setCellValue("限值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(45);
        cell.setCellValue("差值");
        cell.setCellStyle(getStyle(1));

        cell = row3.createCell(46);
        cell.setCellValue("超标天数");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(47);
        cell.setCellValue("最大幅值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(48);
        cell.setCellValue("限值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(49);
        cell.setCellValue("差值");
        cell.setCellStyle(getStyle(1));

        cell = row3.createCell(50);
        cell.setCellValue("超标天数");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(51);
        cell.setCellValue("最大幅值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(52);
        cell.setCellValue("限值");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(53);
        cell.setCellValue("差值");
        cell.setCellStyle(getStyle(1));

        cell = row3.createCell(54);
        cell.setCellValue("3次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(55);
        cell.setCellValue("5次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(56);
        cell.setCellValue("7次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(57);
        cell.setCellValue("11次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(58);
        cell.setCellValue("13次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(59);
        cell.setCellValue("23次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(60);
        cell.setCellValue("25次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(61);
        cell.setCellValue("其他次");
        cell.setCellStyle(getStyle(1));

        cell = row3.createCell(62);
        cell.setCellValue("3次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(63);
        cell.setCellValue("5次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(64);
        cell.setCellValue("7次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(65);
        cell.setCellValue("11次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(66);
        cell.setCellValue("13次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(67);
        cell.setCellValue("23次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(68);
        cell.setCellValue("25次");
        cell.setCellStyle(getStyle(1));
        cell = row3.createCell(69);
        cell.setCellValue("其他次");
        cell.setCellStyle(getStyle(1));

        try{
            for (int i=0;i<list.size();i++){
                os = new ByteArrayOutputStream();
                row =  xssfSheet.createRow(i+3);

                cell = row.createCell(0);
                cell.setCellValue(i+1);

                cell = row.createCell(1);
                cell.setCellValue(list.get(i).getProvinceCompany());

                cell = row.createCell(2);
                cell.setCellValue(list.get(i).getCityCompany());

                cell = row.createCell(3);
                cell.setCellValue(list.get(i).getMonitorName());

                cell = row.createCell(4);
                cell.setCellValue(list.get(i).getMonitorType());

                cell = row.createCell(5);
                cell.setCellValue(list.get(i).getPowerSubstationName());

                cell = row.createCell(6);
                cell.setCellValue(list.get(i).getObjName());

                cell = row.createCell(7);
                cell.setCellValue(list.get(i).getMonitorVoltageLevel());

                cell = row.createCell(8);
                cell.setCellValue(list.get(i).getPlantName());

                cell = row.createCell(9);
                cell.setCellValue(list.get(i).getPlantVolageLevel());

                cell = row.createCell(10);
                cell.setCellValue(list.get(i).getDlcMp());

                cell = row.createCell(11);
                cell.setCellValue(list.get(i).getDevcMp());

                cell = row.createCell(12);
                cell.setCellValue(list.get(i).getXycMp());

                cell = row.createCell(13);
                cell.setCellValue(list.get(i).getOverLimitDay());

                cell = row.createCell(14);
                cell.setCellValue(list.get(i).getOverVoltageDeviationDay());
                cell = row.createCell(15);
                cell.setCellValue(list.get(i).getMaxVoltageDeviationData());
                cell = row.createCell(16);
                cell.setCellValue(list.get(i).getLimitVoltageDeviationData());
                cell = row.createCell(17);
                cell.setCellValue(list.get(i).getDiffVoltageDeviationData());

                cell = row.createCell(18);
                cell.setCellValue(list.get(i).getOverHarmonicCurrentDay());
                cell = row.createCell(19);
                cell.setCellValue(list.get(i).getMaxHarmonicCurrentData());
                cell = row.createCell(20);
                cell.setCellValue(list.get(i).getLimitHarmonicCurrentData());
                cell = row.createCell(21);
                cell.setCellValue(list.get(i).getDiffHarmonicCurrentData());

                cell = row.createCell(22);
                cell.setCellValue(list.get(i).getOverLimitHarmVDay());
                cell = row.createCell(23);
                cell.setCellValue(list.get(i).getMaxLimitHarmVData());
                cell = row.createCell(24);
                cell.setCellValue(list.get(i).getLimitHarmVData());
                cell = row.createCell(25);
                cell.setCellValue(list.get(i).getDiffHarmVData());

                cell = row.createCell(26);
                cell.setCellValue(list.get(i).getOverVoltageDistortionDay());
                cell = row.createCell(27);
                cell.setCellValue(list.get(i).getMaxVoltageDistortionData());
                cell = row.createCell(28);
                cell.setCellValue(list.get(i).getLimitVoltageDistortionData());
                cell = row.createCell(29);
                cell.setCellValue(list.get(i).getDiffVoltageDistortionData());

                cell = row.createCell(30);
                cell.setCellValue(list.get(i).getOverHarmonicVoltageDay());
                cell = row.createCell(31);
                cell.setCellValue(list.get(i).getMaxHarmonicVoltageData());
                cell = row.createCell(32);
                cell.setCellValue(list.get(i).getLimitHarmonicVoltageData());
                cell = row.createCell(33);
                cell.setCellValue(list.get(i).getDiffHarmonicVoltageData());

                cell = row.createCell(34);
                cell.setCellValue(list.get(i).getOverThreeVoltageUnbalanceDay());
                cell = row.createCell(35);
                cell.setCellValue(list.get(i).getMaxThreeVoltageUnbalanceData());
                cell = row.createCell(36);
                cell.setCellValue(list.get(i).getLimitThreeVoltageUnbalanceData());
                cell = row.createCell(37);
                cell.setCellValue(list.get(i).getDiffThreeVoltageUnbalanceData());

                cell = row.createCell(38);
                cell.setCellValue(list.get(i).getOverFrequencyDeviationDay());
                cell = row.createCell(39);
                cell.setCellValue(list.get(i).getMaxFrequencyDeviationData());
                cell = row.createCell(40);
                cell.setCellValue(list.get(i).getLimitFrequencyDeviationData());
                cell = row.createCell(41);
                cell.setCellValue(list.get(i).getDiffFrequencyDeviationData());

                cell = row.createCell(42);
                cell.setCellValue(list.get(i).getOverInterharmonicsDay());
                cell = row.createCell(43);
                cell.setCellValue(list.get(i).getMaxInterharmonicsData());
                cell = row.createCell(44);
                cell.setCellValue(list.get(i).getLimitInterharmonicsData());
                cell = row.createCell(45);
                cell.setCellValue(list.get(i).getDiffInterharmonicsData());

                cell = row.createCell(46);
                cell.setCellValue(list.get(i).getOverNegativeDay());
                cell = row.createCell(47);
                cell.setCellValue(list.get(i).getMaxNegativeDay());
                cell = row.createCell(48);
                cell.setCellValue(list.get(i).getLimitNegativeData());
                cell = row.createCell(49);
                cell.setCellValue(list.get(i).getDiffNegativeData());

                cell = row.createCell(50);
                cell.setCellValue(list.get(i).getOverFlickerDay());
                cell = row.createCell(51);
                cell.setCellValue(list.get(i).getMaxFlickerData());
                cell = row.createCell(52);
                cell.setCellValue(list.get(i).getLimitFlickerData());
                cell = row.createCell(53);
                cell.setCellValue(list.get(i).getDiffFlickerData());

                cell = row.createCell(54);
                cell.setCellValue(list.get(i).getOverVoltageThreeTimes());
                cell = row.createCell(55);
                cell.setCellValue(list.get(i).getOverVoltageFiveTimes());
                cell = row.createCell(56);
                cell.setCellValue(list.get(i).getOverVoltageSevenTimes());
                cell = row.createCell(57);
                cell.setCellValue(list.get(i).getOverVoltageElevenTimes());
                cell = row.createCell(58);
                cell.setCellValue(list.get(i).getOverVoltageThirteenTimes());
                cell = row.createCell(59);
                cell.setCellValue(list.get(i).getOverVoltageTwentyThirdTimes());
                cell = row.createCell(60);
                cell.setCellValue(list.get(i).getOverVoltageTwentyFiveTimes());
                cell = row.createCell(61);
                cell.setCellValue(list.get(i).getOverVoltageOtherTimes());

                cell = row.createCell(62);
                cell.setCellValue(list.get(i).getOverCurrentThreeTimes());
                cell = row.createCell(63);
                cell.setCellValue(list.get(i).getOverCurrentFiveTimes());
                cell = row.createCell(64);
                cell.setCellValue(list.get(i).getOverCurrentSevenTimes());
                cell = row.createCell(65);
                cell.setCellValue(list.get(i).getOverCurrentElevenTimes());
                cell = row.createCell(66);
                cell.setCellValue(list.get(i).getOverCurrentThirteenTimes());
                cell = row.createCell(67);
                cell.setCellValue(list.get(i).getOverCurrentTwentyThirdTimes());
                cell = row.createCell(68);
                cell.setCellValue(list.get(i).getOverCurrentTwentyFiveTimes());
                cell = row.createCell(69);
                cell.setCellValue(list.get(i).getOverCurrentOtherTimes());

                cell = row.createCell(70);
                cell.setCellValue(list.get(i).getMonitorNumber());
                xssfWorkbook.write(os);
            }

            //设置response参数，可以打开下载界面
            response.reset();
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xlsx").getBytes(), "iso-8859-1"));
            ServletOutputStream out = response.getOutputStream();
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            byte[] content = os.toByteArray();
            is = new ByteArrayInputStream(content);
            bis = new BufferedInputStream(is);
            bos = new BufferedOutputStream(out);
            byte[] buff = new byte[2048];
            int bytesRead;
            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
            bis.close();
            bos.close();
        } catch (IOException e) {
            logger.error("异常为："+e.toString());
        }
    }


    /**
     * 表头样式
     */
    private XSSFCellStyle getStyle(int i) {
        XSSFCellStyle result = null;
        if (i == 1){
            result = xssfWorkbook.createCellStyle();
            XSSFFont font = xssfWorkbook.createFont();
            font.setFontName("黑体");
            font.setBold(true);
            //font.setFontHeightInPoints((short) 12);//设置字体大小
            result.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            result.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            result.setFont(font);
        } else if (i == 2){
            result = xssfWorkbook.createCellStyle();
            XSSFFont font = xssfWorkbook.createFont();
            font.setFontName("宋体");
            result.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            result.setAlignment(HSSFCellStyle.ALIGN_LEFT);
            result.setFont(font);
        }else if (i == 3){
            result = xssfWorkbook.createCellStyle();
            XSSFFont font = xssfWorkbook.createFont();
            font.setFontName("宋体");
            result.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            result.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            result.setFont(font);
        }
        return result;
    }

    /**
     * 保留小数
     * @param num
     * @return
     */
    private String saveTwoNumber(double num){
        return String.format("%.2f",num);
    }

}
