package com.sifang.modules.customer.excel;

import com.sifang.modules.supply.stock.excel.MaterialStockExcel;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.util.IOUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

public class FileExportUtil {

    /**
     * 日报导出excel
     */
    public static void exportDailyRecodeExcel(List<DailyRecodeExcel> list, HttpServletResponse response,String creatTime) {
        /** 第一步，创建一个Workbook，对应一个Excel文件  */
        XSSFWorkbook wb = new XSSFWorkbook();
        /** 第二步，在Workbook中添加一个sheet,对应Excel文件中的sheet  */
        XSSFSheet sheet = wb.createSheet(creatTime + "日报统计");
        /** 第三步，设置样式以及字体样式*/
        XSSFCellStyle titleStyle = createTitleCellStyle(wb);
        XSSFCellStyle headerStyle = createHeadCellStyle(wb);
        XSSFCellStyle contentStyle = createContentCellStyle(wb);
        /** 第四步，创建标题 ,合并标题单元格 */
        // 行号
        int rowNum = 0;
        // 创建第一页的第一行，索引从0开始
        XSSFRow row0 = sheet.createRow(rowNum++);
        row0.setHeight((short) 600);// 设置行高

        String[] row_Text = {"省  区", "负责人", "代理商签约", "","", "发货量（MW）", "", "进件数量（个）",  "", "安装量 提交验工验收（MW）","","安装量 终审通过(MW)","","并网量 终审通过（MW）",""};
        for (int i = 0; i < row_Text.length; i++) {
            XSSFCell c00 = row0.createCell(i);
            c00.setCellValue(row_Text[i]);
            c00.setCellStyle(headerStyle);
        }
        // 合并单元格，参数依次为起始列，结束列，起始行，结束行 （索引0开始）
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 2, 4));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 5, 6));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 7, 8));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 9, 10));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 11, 12));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 13, 14));
        //第二行
        XSSFRow row2 = sheet.createRow(rowNum++);
        row2.setHeight((short) 700);
        String[] row_third = {"","", "当日签约数量", "累计签约数量", "有进件的签约数量", "当日发货量", "本月发货量", "当日进件数量", "本月进件数量", "当日安装量", "本月安装量", "当日安装量", "本月安装量", "当日并网量", "本月并网量"};
        for (int i = 0; i < row_third.length; i++) {
            XSSFCell tempCell = row2.createCell(i);
            tempCell.setCellValue(row_third[i]);
            tempCell.setCellStyle(headerStyle);
        }
        for (DailyRecodeExcel value : list) {
            XSSFRow tempRow = sheet.createRow(rowNum++);
            tempRow.setHeight((short) 500);
            // 循环单元格填入数据
            for (int j = 0; j < 15; j++) {
                //列宽自适应，j为自适应的列，true就是自适应，false就是不自适应，默认不自适应
                sheet.autoSizeColumn(j, true);
                XSSFCell tempCell = tempRow.createCell(j);
                tempCell.setCellStyle(contentStyle);
                String tempValue = "";
                switch (j) {
                    case 0:
                        tempValue = value.getProvince();
                        break;
                    case 1:
                        tempValue = value.getLeaderName();
                        break;
                    case 2:
                        tempValue = value.getSignedCntDay().stripTrailingZeros().toPlainString();
                        break;
                    case 3:
                        tempValue = value.getCumSignedCnt().stripTrailingZeros().toPlainString();
                        break;
                    case 4:
                        tempValue = value.getSignedCntWithApp().stripTrailingZeros().toPlainString();
                        break;
                    case 5:
                        tempValue = value.getShippedCntDay().stripTrailingZeros().toPlainString();
                        break;
                    case 6:
                        tempValue = value.getShippedCntMonth().stripTrailingZeros().toPlainString();
                        break;
                    case 7:
                        tempValue = value.getAppCntDay().stripTrailingZeros().toPlainString();
                        break;
                    case 8:
                        tempValue = value.getAppCntMonth().stripTrailingZeros().toPlainString();
                        break;
                    case 9:
                        tempValue = value.getSubmittedDay().stripTrailingZeros().toPlainString();
                        break;
                    case 10:
                        tempValue = value.getSubmittedMonth().stripTrailingZeros().toPlainString();
                        break;
                    case 11:
                        tempValue = value.getFinalApprovedDay().stripTrailingZeros().toPlainString();
                        break;
                    case 12:
                        tempValue = value.getFinalApprovedMonth().stripTrailingZeros().toPlainString();
                        break;
                    case 13:
                        tempValue = value.getGridConnectedDay().stripTrailingZeros().toPlainString();
                        break;
                    case 14:
                        tempValue = value.getGridConnectedMonth().stripTrailingZeros().toPlainString();
                        break;
                }
                tempCell.setCellValue(tempValue);
            }
        }
        //导出到浏览器下载
        buildExcelDocument(creatTime + "日报统计.xlsx", wb, response);
    }

    /**
     * 可授信账户列表导出
     */
    public static void exportAccountExcel(List<AccountDetailExcel> list,HttpServletResponse response,String creatTime){
        /** 第一步，创建一个Workbook，对应一个Excel文件  */
        XSSFWorkbook wb = new XSSFWorkbook();
        /** 第二步，在Workbook中添加一个sheet,对应Excel文件中的sheet  */
        XSSFSheet sheet = wb.createSheet(creatTime + "账户明细");
        /** 第三步，设置样式以及字体样式*/
        XSSFCellStyle titleStyle = createTitleCellStyle(wb);
        XSSFCellStyle headerStyle = createHeadCellStyle(wb);
        XSSFCellStyle contentStyle = createContentCellStyle(wb);
        /** 第四步，创建标题 ,合并标题单元格 */
        // 行号
        int rowNum = 0;
        // 创建第一页的第一行，索引从0开始
        XSSFRow row0 = sheet.createRow(rowNum++);
        row0.setHeight((short) 600);// 设置行高

        String[] row_Text = {"  代理商名称     ", "实缴保证金余额(元)", "","", "保证金额度(元)", "历史阶段踏勘量(W)", "累计已发货(元)","", "", "累计已安装(元)","","","累计已并网(元)","",""};
        for (int i = 0; i < row_Text.length; i++) {
            XSSFCell c00 = row0.createCell(i);
            c00.setCellValue(row_Text[i]);
            c00.setCellStyle(headerStyle);
        }
        // 合并单元格，参数依次为起始行号，终止行号， 起始列号，终止列号
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 1, 3));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 6, 8));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 9, 11));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 12, 14));
        //第二行
        XSSFRow row2 = sheet.createRow(rowNum++);
        row2.setHeight((short) 700);
        String[] row_third = {"","实缴保证金", "历史数据", "合计", "", "", "已发货", "历史数据", "合计", "已安装", "历史数据", "合计", "已并网", "历史数据", "合计"};
        for (int i = 0; i < row_third.length; i++) {
            XSSFCell tempCell = row2.createCell(i);
            tempCell.setCellValue(row_third[i]);
            tempCell.setCellStyle(headerStyle);
        }
        for (AccountDetailExcel value : list) {
            XSSFRow tempRow = sheet.createRow(rowNum++);
            tempRow.setHeight((short) 500);
            // 循环单元格填入数据
            for (int j = 0; j < 15; j++) {
                //列宽自适应，j为自适应的列，true就是自适应，false就是不自适应，默认不自适应
                sheet.autoSizeColumn(j, true);
                XSSFCell tempCell = tempRow.createCell(j);
                tempCell.setCellStyle(contentStyle);
                String tempValue = "";
                switch (j) {
                    case 0:
                        tempValue = value.getTraderName();
                        break;
                    case 1:
                        tempValue = value.getBzjAmount().stripTrailingZeros().toPlainString();
                        break;
                    case 2:
                        tempValue = value.getYkBzjAmount().stripTrailingZeros().toPlainString();
                        break;
                    case 3:
                        tempValue = value.getTotalOne().stripTrailingZeros().toPlainString();
                        break;
                    case 4:
                        tempValue = value.getBondAmountLimit().stripTrailingZeros().toPlainString();
                        break;
                    case 5:
                        tempValue = value.getYkTklTotalCapacity().stripTrailingZeros().toPlainString();
                        break;
                    case 6:
                        tempValue = value.getDeliverTotalAmount().stripTrailingZeros().toPlainString();
                        break;
                    case 7:
                        tempValue = value.getYkDeliverTotalCapacity().stripTrailingZeros().toPlainString();
                        break;
                    case 8:
                        tempValue = value.getTotalTwo().stripTrailingZeros().toPlainString();
                        break;
                    case 9:
                        tempValue = value.getYazTotalCapacity().stripTrailingZeros().toPlainString();
                        break;
                    case 10:
                        tempValue = value.getYkYazTotalCapacity().stripTrailingZeros().toPlainString();
                        break;
                    case 11:
                        tempValue = value.getTotalThree().stripTrailingZeros().toPlainString();
                        break;
                    case 12:
                        tempValue = value.getYbwTotalCapacity().stripTrailingZeros().toPlainString();
                        break;
                    case 13:
                        tempValue = value.getYkYbwTotalCapacity().stripTrailingZeros().toPlainString();
                        break;
                    case 14:
                        tempValue = value.getTotalFour().stripTrailingZeros().toPlainString();
                        break;
                }
                tempCell.setCellValue(tempValue);
            }
        }
        //导出到浏览器下载
        buildExcelDocument(creatTime + "账户明细.xlsx", wb, response);
    }

    /**
     *  代理商库存统计导出
     */
    public static void  exportMaterialStockExcel(List<MaterialStockExcel> list, HttpServletResponse response,String creatTime) {
        /** 第一步，创建一个Workbook，对应一个Excel文件  */
        XSSFWorkbook wb = new XSSFWorkbook();
        /** 第二步，在Workbook中添加一个sheet,对应Excel文件中的sheet  */
        XSSFSheet sheet = wb.createSheet(creatTime + "代理商库存统计");
        /** 第三步，设置样式以及字体样式*/
        XSSFCellStyle titleStyle = createTitleCellStyle(wb);
        XSSFCellStyle headerStyle = createHeadCellStyle(wb);
        XSSFCellStyle contentStyle = createContentCellStyle(wb);
        /** 第四步，创建标题 ,合并标题单元格 */
        // 行号
        int rowNum = 0;
        // 创建第一页的第一行，索引从0开始
        XSSFRow row0 = sheet.createRow(rowNum++);
        row0.setHeight((short) 600);// 设置行高

        String[] row_Text = {"物料代码", "外部编码", "物料名称", "物料类型","物料规格", "库存单位", "供应商名称", "仓库名称",  "累计已发货","", "","累计已安装","", "","累计已发电","", "",
                "累计已投放","安装未发电","安装未投放","累计退货","累计买断","可用总库存","","待发货","待签收","在库30天以内","","在库30(天)-60天","","在库60(天)-90天","","在库90天及以上",""};
        for (int i = 0; i < row_Text.length; i++) {
            XSSFCell c00 = row0.createCell(i);
            c00.setCellValue(row_Text[i]);
            c00.setCellStyle(headerStyle);
        }

        sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 6, 6));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 7, 7));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 8, 10));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 11, 13));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 14, 16));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 17, 17));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 18, 18));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 19, 19));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 20, 20));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 21, 21));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 22, 23));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 24, 24));
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 25, 25));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 26, 27));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 28, 29));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 30, 31));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 32, 33));
        //第二行
        XSSFRow row2 = sheet.createRow(rowNum++);
        row2.setHeight((short) 700);
        String[] row_third = {"","", "", "", "", "", "", "","户用","历史数据","合计","户用","历史数据","合计","户用","历史数据","合计",  "", "", "", "","", "数量", "金额（元）", "","","数量", "金额（元）", "数量", "金额（元）", "数量", "金额（元）", "数量", "金额（元）"};
        for (int i = 0; i < row_third.length; i++) {
            XSSFCell tempCell = row2.createCell(i);
            tempCell.setCellValue(row_third[i]);
            tempCell.setCellStyle(headerStyle);
        }
        for (MaterialStockExcel value : list) {
            XSSFRow tempRow = sheet.createRow(rowNum++);
            tempRow.setHeight((short) 500);
            // 循环单元格填入数据
            for (int j = 0; j < 34; j++) {
                //列宽自适应，j为自适应的列，true就是自适应，false就是不自适应，默认不自适应
                sheet.autoSizeColumn(j, true);
                XSSFCell tempCell = tempRow.createCell(j);
                tempCell.setCellStyle(contentStyle);
                String tempValue = "";
                switch (j) {
                    case 0:
                        tempValue = value.getCode();
                        break;
                    case 1:
                        tempValue = value.getQqCode();
                        break;
                    case 2:
                        tempValue = value.getMaterialName();
                        break;
                    case 3:
                        tempValue = value.getMaterialType();
                        break;
                    case 4:
                        tempValue = value.getMaterialSpec();
                        break;
                    case 5:
                        tempValue = value.getMaterialUnit();
                        break;
                    case 6:
                        tempValue = value.getMaterialBrand();
                        break;
                    case 7:
                        tempValue = value.getWarehouseName();
                        break;
                    case 8:
                        tempValue = value.getYfhTotalCapacity();
                        break;
                    case 9:
                        tempValue = value.getYkYfhAmount();
                        break;
                    case 10:
                        tempValue = value.getTotal1();
                        break;
                    case 11:
                        tempValue = value.getYazTotalCapacity();
                        break;
                    case 12:
                        tempValue = value.getYkYazAmount();
                        break;
                    case 13:
                        tempValue = value.getTotal2();
                        break;
                    case 14:
                        tempValue = value.getYfdTotalCapacity();
                        break;
                    case 15:
                        tempValue = value.getYkYfdAmount();
                        break;
                    case 16:
                        tempValue = value.getTotal3();
                        break;
                    case 17:
                        tempValue = value.getYtfTotalCapacity();
                        break;
                    case 18:
                        tempValue = value.getAzwfdTotalCapacity();
                        break;
                    case 19:
                        tempValue = value.getAzwtfTotalCapacity();
                        break;
                    case 20:
                        tempValue = value.getYkThAmount();
                        break;
                    case 21:
                        tempValue = value.getYkMdAmount();
                        break;
                    case 22:
                        tempValue = value.getWarning();
                        break;
                    case 23:
                        tempValue = value.getTotalPrice();
                        break;
                    case 24:
                        tempValue = value.getWaitDeliverNum();
                        break;
                    case 25:
                        tempValue = value.getWaitSignCount();
                        break;
                    case 26:
                        tempValue = value.getNumOne();
                        break;
                    case 27:
                        tempValue = value.getPriceOne();
                        break;
                    case 28:
                        tempValue = value.getNumTwo();
                        break;
                    case 29:
                        tempValue = value.getPriceTwo();
                        break;
                    case 30:
                        tempValue = value.getNumThree();
                        break;
                    case 31:
                        tempValue = value.getPriceThree();
                        break;
                    case 32:
                        tempValue = value.getNumFour();
                        break;
                    case 33:
                        tempValue = value.getPriceFour();
                        break;
                }
                tempCell.setCellValue(tempValue);
            }
        }
        //导出到浏览器下载
        buildExcelDocument(creatTime + "代理商库存.xlsx", wb, response);
    }

    /**
     * 周报导出excel
     */
    public static void exportWeeklyRecodeExcel(List<WeeklyRecodeExcel> list, HttpServletResponse response,String startDate,String endDate) {
        /** 第一步，创建一个Workbook，对应一个Excel文件  */
        XSSFWorkbook wb = new XSSFWorkbook();
        /** 第二步，在Workbook中添加一个sheet,对应Excel文件中的sheet  */
        XSSFSheet sheet = wb.createSheet(startDate+"~"+endDate+ "周报统计");
        /** 第三步，设置样式以及字体样式*/
        XSSFCellStyle titleStyle = createTitleCellStyle(wb);
        XSSFCellStyle headerStyle = createHeadCellStyle(wb);
        XSSFCellStyle contentStyle = createContentCellStyle(wb);
        /** 第四步，创建标题 ,合并标题单元格 */
        // 行号
        int rowNum = 0;
        // 创建第一页的第一行，索引从0开始
        XSSFRow row0 = sheet.createRow(rowNum++);
        row0.setHeight((short) 600);// 设置行高

        String[] row_Text = {"省  区", "负责人", "代理商签约", "", "发货量（MW）", "","","","", "进件用户数量（个）",  "","", "安装量 提交验工验收（MW）","","","","","安装量 终审通过(MW)","","","并网量 终审通过（MW）","",""};
        for (int i = 0; i < row_Text.length; i++) {
            XSSFCell c00 = row0.createCell(i);
            c00.setCellValue(row_Text[i]);
            c00.setCellStyle(headerStyle);
        }
        // 合并单元格，参数依次为起始行号，终止行号， 起始列号，终止列号
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));//第一列  跨两行
        sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 2, 3));//第三列  跨2列
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 4, 8));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 9, 11));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 12, 16));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 17, 19));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 20, 22));
        //第二行
        XSSFRow row2 = sheet.createRow(rowNum++);
        row2.setHeight((short) 700);
        String[] row_third = {"","", "上周完成数量", "累计数量", "上周目标", "上周已发","推进率", "本月发货量","年度发货量", "上周进件量", "本月进件量","年度进件量", "上周安装量","本月目标", "本月安装量","推进率","年度安装量", "上周安装量", "本月安装量","年度安装量", "上周并网量", "本月并网量","年度并网量"};
        for (int i = 0; i < row_third.length; i++) {
            XSSFCell tempCell = row2.createCell(i);
            tempCell.setCellValue(row_third[i]);
            tempCell.setCellStyle(headerStyle);
        }
        for (WeeklyRecodeExcel value : list) {
            XSSFRow tempRow = sheet.createRow(rowNum++);
            tempRow.setHeight((short) 500);
            // 循环单元格填入数据
            for (int j = 0; j < 23; j++) {
                //列宽自适应，j为自适应的列，true就是自适应，false就是不自适应，默认不自适应
                sheet.autoSizeColumn(j, true);
                XSSFCell tempCell = tempRow.createCell(j);
                tempCell.setCellStyle(contentStyle);
                String tempValue = "";
                switch (j) {
                    case 0:
                        tempValue = value.getProvince();
                        break;
                    case 1:
                        tempValue = value.getLeaderName();
                        break;
                    case 2:
                        tempValue = value.getSignedCntWeek().stripTrailingZeros().toPlainString();
                        break;
                    case 3:
                        tempValue = value.getCumSignedCnt().stripTrailingZeros().toPlainString();
                        break;
                    case 4:
                    case 6:
                    case 13:
                    case 15:
                        tempValue = "";
                        break;
                    case 5:
                        tempValue = value.getShippedCntWeek().stripTrailingZeros().toPlainString();
                        break;
                    case 7:
                        tempValue = value.getShippedCntMonth().stripTrailingZeros().toPlainString();
                        break;
                    case 8:
                        tempValue = value.getShippedCntYear().stripTrailingZeros().toPlainString();
                        break;
                    case 9:
                        tempValue = value.getAppCntWeek().stripTrailingZeros().toPlainString();
                        break;
                    case 10:
                        tempValue = value.getAppCntMonth().stripTrailingZeros().toPlainString();
                        break;
                    case 11:
                        tempValue = value.getAppCntYear().stripTrailingZeros().toPlainString();
                        break;
                    case 12:
                        tempValue = value.getSubmittedWeek().stripTrailingZeros().toPlainString();
                        break;
                    case 14:
                        tempValue = value.getSubmittedMonth().stripTrailingZeros().toPlainString();
                        break;
                    case 16:
                        tempValue = value.getSubmittedYear().stripTrailingZeros().toPlainString();
                        break;
                    case 17:
                        tempValue = value.getFinalApprovedWeek().stripTrailingZeros().toPlainString();
                        break;
                    case 18:
                        tempValue = value.getFinalApprovedMonth().stripTrailingZeros().toPlainString();
                        break;
                    case 19:
                        tempValue = value.getFinalApprovedYear().stripTrailingZeros().toPlainString();
                        break;
                    case 20:
                        tempValue = value.getGridConnectedWeek().stripTrailingZeros().toPlainString();
                        break;
                    case 21:
                        tempValue = value.getGridConnectedMonth().stripTrailingZeros().toPlainString();
                        break;
                    case 22:
                        tempValue = value.getGridConnectedYear().stripTrailingZeros().toPlainString();
                        break;
                }
                tempCell.setCellValue(tempValue);
            }
        }
        //导出到浏览器下载
        buildExcelDocument(startDate+"~"+endDate+ "周报统计.xlsx", wb, response);
    }

    /**
     * @Description: [导出到浏览器]
     * @Param: [fileName, wb, response]
     */
    private static void buildExcelDocument(String fileName, Workbook wb, HttpServletResponse response) {
        try {
            response.setContentType("application/octet-stream");
            // 可自行定义编码格式
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
            //清除jsp编译html文件的空白,防止excel出现空行
            response.flushBuffer();
            //写出
            wb.write(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
//---------------------------------------以下是封装的样式-----------------------------

    /**
     * 创建标题样式
     *
     * @param wb
     * @return
     */
    private static XSSFCellStyle createTitleCellStyle(XSSFWorkbook wb) {
        XSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直对齐
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
//        cellStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());//背景颜色

        XSSFFont headerFont1 = (XSSFFont) wb.createFont(); // 创建字体样式
        headerFont1.setBold(true); //字体加粗
        headerFont1.setFontName("黑体"); // 设置字体类型
        headerFont1.setFontHeightInPoints((short) 15); // 设置字体大小
        cellStyle.setFont(headerFont1); // 为标题样式设置字体样式
        return cellStyle;
    }

    /**
     * 创建表头样式
     *
     * @param wb
     * @return
     */
    private static XSSFCellStyle createHeadCellStyle(XSSFWorkbook wb) {
        XSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setWrapText(true);// 设置自动换行
        cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());//背景颜色
        cellStyle.setAlignment(HorizontalAlignment.CENTER); //水平居中
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //垂直对齐
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
//        cellStyle.setBottomBorderColor(IndexedColors.BLACK.index);
        cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
        cellStyle.setBorderLeft(BorderStyle.THIN); //左边框
        cellStyle.setBorderRight(BorderStyle.THIN); //右边框
        cellStyle.setBorderTop(BorderStyle.THIN); //上边框

        XSSFFont headerFont = (XSSFFont) wb.createFont(); // 创建字体样式
        headerFont.setBold(true); //字体加粗
        headerFont.setFontName("黑体"); // 设置字体类型
        headerFont.setFontHeightInPoints((short) 12); // 设置字体大小
        cellStyle.setFont(headerFont); // 为标题样式设置字体样式

        return cellStyle;
    }

    /**
     * 创建内容样式
     *
     * @param wb
     * @return
     */
    private static XSSFCellStyle createContentCellStyle(XSSFWorkbook wb) {
        XSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中
        cellStyle.setAlignment(HorizontalAlignment.CENTER);// 水平居中
        cellStyle.setWrapText(true);// 设置自动换行
        cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
        cellStyle.setBorderLeft(BorderStyle.THIN); //左边框
        cellStyle.setBorderRight(BorderStyle.THIN); //右边框
        cellStyle.setBorderTop(BorderStyle.THIN); //上边框

        // 生成12号字体
        XSSFFont font = wb.createFont();
        font.setColor((short) 8);
        font.setFontHeightInPoints((short) 12);
        cellStyle.setFont(font);

        return cellStyle;
    }
}
