package cn.palmte.work.utils.excel;

import cn.palmte.work.bean.*;
import cn.palmte.work.model.*;
import cn.palmte.work.utils.DateKit;
import cn.palmte.work.utils.ObjectKit;
import cn.palmte.work.utils.Utils;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import top.jfunc.common.db.bean.Record;

import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * created by Yuanping Zhang
 * 2022/08/01
 */
public class ExportExcelUtils {
    private XSSFWorkbook workbook;
    private CellStyle style2; // 内容样式
    private CellStyle style; // 标题样式
    public ExportExcelUtils(){
        workbook = new XSSFWorkbook();
        style = workbook.createCellStyle();
        // 设置这些样式
        style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex());
        style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex());
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        style.setBorderBottom(BorderStyle.THIN);
        style.setBorderLeft(BorderStyle.THIN);
        style.setBorderRight(BorderStyle.THIN);
        style.setBorderTop(BorderStyle.THIN);
        style.setAlignment(HorizontalAlignment.CENTER);
        // 生成一个字体
        Font font = workbook.createFont();
        font.setBold(false);
        // 把字体应用到当前的样式
        style.setFont(font);

        style2 = workbook.createCellStyle();
        style2.setFillForegroundColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex());
        style2.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex());
        style2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        style2.setBorderBottom(BorderStyle.THIN);
        style2.setBorderLeft(BorderStyle.THIN);
        style2.setBorderRight(BorderStyle.THIN);
        style2.setBorderTop(BorderStyle.THIN);
        style2.setAlignment(HorizontalAlignment.LEFT);
        style2.setVerticalAlignment(VerticalAlignment.CENTER);
        // 生成另一个字体
        Font font2 = workbook.createFont();
        font2.setBold(false);
        // 把字体应用到当前的样式
        style2.setFont(font2);

//        // 产生表格标题行
//        Row row = sheet.createRow(0);
//        for(short i = 0; i < headers.length; i++){
//            Cell cell = row.createCell(i);
//            cell.setCellStyle(style);
//            cell.setCellType(CellType.STRING);
//            cell.setCellValue(headers[i]);
//        }
    }

    /**
     * 项目管理项目基本信息与其他信息工作簿
     *
     * @param pattern
     *            如果有时间数据，设定输出格式。默认为"yyyy-MM-dd"
     * @param rowIndex
     *
     * @throws IOException
     */
    public void exportProjectExcel(String[] headers, String[] columns, Project project, String pattern, int rowIndex, String sheetName, OutputStream outputStream) throws IOException{
        // 遍历集合数据，产生数据行
        int index = rowIndex;
        XSSFSheet sheet = workbook.createSheet(sheetName);
        sheet.setDefaultColumnWidth((short)20);
        Font font3 = workbook.createFont();
        font3.setColor(HSSFColor.HSSFColorPredefined.BLUE.getIndex());
        for (int i = 0; i < columns.length; i++){
            Row row = sheet.createRow(index++);
            Cell firstCell = row.createCell(0);
            firstCell.setCellStyle(style);
            firstCell.setCellType(CellType.STRING);
            firstCell.setCellValue(headers[i]);
            Cell secondCell = row.createCell(1);
            secondCell.setCellStyle(style2);
            Object value = ObjectKit.get(project, columns[i]);
            if(value == null){
                secondCell.setCellType(CellType.STRING);
                secondCell.setCellValue("");
            }else{
                if(value instanceof Integer){
                    secondCell.setCellType(CellType.NUMERIC);
                    secondCell.setCellValue((int)value);
                } else if(value instanceof Long){
                    secondCell.setCellType(CellType.NUMERIC);
                    secondCell.setCellValue((long)value);
                } else if(value instanceof Double){
                    secondCell.setCellType(CellType.NUMERIC);
                    secondCell.setCellValue((double)value);
                } else if(value instanceof BigDecimal){
                    secondCell.setCellType(CellType.NUMERIC);
                    secondCell.setCellValue(Utils.format(((BigDecimal)value)));
                } else if(value instanceof Date){
                    secondCell.setCellType(CellType.STRING);
                    String date_str = DateKit.toStr((Date) value, pattern);
                    secondCell.setCellValue(date_str);
                } else{
                    secondCell.setCellType(CellType.STRING);
                    secondCell.setCellValue(value.toString());
                }
            }
        }
    }

    public void exportBudgetExcel(BudgetBean budgetBean, CashFlowBean cashFlowBean, int rowIndex, String sheetName, ServletOutputStream outputStream, String otherName) {
        // 遍历集合数据，产生数据行
        int index = rowIndex;
        XSSFSheet sheet = workbook.createSheet(sheetName);
        sheet.setDefaultColumnWidth((short)20);
        Font font3 = workbook.createFont();
        font3.setColor(HSSFColor.HSSFColorPredefined.BLUE.getIndex());
        // 收入
        Row incomeRow = sheet.createRow(index++);
        createTitleRow(incomeRow, "收入");
        index = createIncomeRow(budgetBean, sheet, index);
        index = index + 3;
        // 成本
        Row costRow = sheet.createRow(index++);
        createTitleRow(costRow, "成本");
        index = createCostRow(budgetBean, sheet, index, otherName);
        index = index + 3;
        // 管理
        Row manageRow = sheet.createRow(index++);
        createTitleRow(manageRow, "管理");
        index = createManageRow(budgetBean, sheet, index);
        index = index + 3;
        // 利润率计算
        Row profitRow = sheet.createRow(index++);
        createTitleRow(profitRow, "利润率计算");
        index = createProfitRow(budgetBean, sheet, index);
        index = index + 3;
        // 现金流量表
        Row cashFLowRow = sheet.createRow(index++);
        createTitleRow(cashFLowRow, "现金流量表");
        createCashFlowRow(cashFlowBean, sheet, index);
    }


    private void createTitleRow(Row row, String titleName) {
        Cell cell = row.createCell(0);
        cell.setCellStyle(style);
        cell.setCellType(CellType.STRING);
        cell.setCellValue(titleName);
    }

    private int createIncomeRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        createSubTitleIncomeRow(sheet, index++);
        createDeviceIncomeRow(budgetBean, sheet, index++);
        createEngineerIncomeRow(budgetBean, sheet, index++);
        createServiceIncomeRow(budgetBean, sheet, index++);
        createTotalIncomeRow(budgetBean, sheet, index++);
        return index;
    }

    private void createSubTitleIncomeRow(XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("类别");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("费用");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style);
        thirdCell.setCellType(CellType.STRING);
        thirdCell.setCellValue("含税金额(元)");
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style);
        fourthCell.setCellType(CellType.STRING);
        fourthCell.setCellValue("不含税金额(元)");
    }

    private void createDeviceIncomeRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("收入");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("设备类");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.NUMERIC);
        thirdCell.setCellValue(Utils.format(budgetBean.getIncomeDeviceTaxInclude()));
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style2);
        fourthCell.setCellType(CellType.NUMERIC);
        fourthCell.setCellValue(Utils.format(budgetBean.getIncomeDeviceTaxExclude()));
    }

    private void createEngineerIncomeRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("收入");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("工程类");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.NUMERIC);
        thirdCell.setCellValue(Utils.format(budgetBean.getIncomeEngineerTaxInclude()));
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style2);
        fourthCell.setCellType(CellType.NUMERIC);
        fourthCell.setCellValue(Utils.format(budgetBean.getIncomeEngineerTaxExclude()));
    }

    private void createServiceIncomeRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("收入");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("服务类");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.NUMERIC);
        thirdCell.setCellValue(Utils.format(budgetBean.getIncomeServiceTaxInclude()));
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style2);
        fourthCell.setCellType(CellType.NUMERIC);
        fourthCell.setCellValue(Utils.format(budgetBean.getIncomeServiceTaxExclude()));
    }

    private void createTotalIncomeRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("合计");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.NUMERIC);
        thirdCell.setCellValue(Utils.format(budgetBean.getIncomeTotalTaxInclude()));
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style2);
        fourthCell.setCellType(CellType.NUMERIC);
        fourthCell.setCellValue(Utils.format(budgetBean.getIncomeTotalTaxExclude()));
    }

    private int createCostRow(BudgetBean budgetBean, XSSFSheet sheet, int index, String otherName) {
        createSubTitleCostRow(sheet, index++);
        createDeviceCostRow(budgetBean, sheet, index++);
        createEngineerCostRow(budgetBean, sheet, index++);
        createServiceCostRow(budgetBean, sheet, index++);
        createOtherCostRow(budgetBean, sheet, index++);
        createManageCostRow(budgetBean, sheet, index++);
        createOtherRow(budgetBean, sheet, index++, otherName);
        createTotalCostRow(budgetBean, sheet, index++);
        return index;
    }

    private void createSubTitleCostRow(XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("类别");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("费用");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style);
        thirdCell.setCellType(CellType.STRING);
        thirdCell.setCellValue("费用项目");
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style);
        fourthCell.setCellType(CellType.STRING);
        fourthCell.setCellValue("含税金额(元)");
        Cell fifthCell = row.createCell(4);
        fifthCell.setCellStyle(style);
        fifthCell.setCellType(CellType.STRING);
        fifthCell.setCellValue("不含税金额(元)");
    }

    private void createDeviceCostRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("成本");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("采购成本");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.STRING);
        thirdCell.setCellValue("设备");
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style2);
        fourthCell.setCellType(CellType.NUMERIC);
        fourthCell.setCellValue(Utils.format(budgetBean.getCostPurchaseDeviceTaxInclude()));
        Cell fifthCell = row.createCell(4);
        fifthCell.setCellStyle(style2);
        fifthCell.setCellType(CellType.NUMERIC);
        fifthCell.setCellValue(Utils.format(budgetBean.getCostPurchaseDeviceTaxExclude()));
    }

    private void createEngineerCostRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("成本");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("采购成本");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.STRING);
        thirdCell.setCellValue("施工");
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style2);
        fourthCell.setCellType(CellType.NUMERIC);
        fourthCell.setCellValue(Utils.format(budgetBean.getCostPurchaseBuildTaxInclude()));
        Cell fifthCell = row.createCell(4);
        fifthCell.setCellStyle(style2);
        fifthCell.setCellType(CellType.NUMERIC);
        fifthCell.setCellValue(Utils.format(budgetBean.getCostPurchaseBuildTaxExclude()));
    }

    private void createServiceCostRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("成本");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("采购成本");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.STRING);
        thirdCell.setCellValue("服务");
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style2);
        fourthCell.setCellType(CellType.NUMERIC);
        fourthCell.setCellValue(Utils.format(budgetBean.getCostPurchaseServiceTaxInclude()));
        Cell fifthCell = row.createCell(4);
        fifthCell.setCellStyle(style2);
        fifthCell.setCellType(CellType.NUMERIC);
        fifthCell.setCellValue(Utils.format(budgetBean.getCostPurchaseServiceTaxExclude()));
    }

    private void createOtherCostRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("成本");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("采购成本");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.STRING);
        thirdCell.setCellValue("其他");
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style2);
        fourthCell.setCellType(CellType.NUMERIC);
        fourthCell.setCellValue(Utils.format(budgetBean.getCostPurchaseOtherTaxInclude()));
        Cell fifthCell = row.createCell(4);
        fifthCell.setCellStyle(style2);
        fifthCell.setCellType(CellType.NUMERIC);
        fifthCell.setCellValue(Utils.format(budgetBean.getCostPurchaseOtherTaxExclude()));
    }

    private void createManageCostRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("成本");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("项目管理成本");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.STRING);
        thirdCell.setCellValue("项目管理成本");
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style2);
        fourthCell.setCellType(CellType.NUMERIC);
        fourthCell.setCellValue(Utils.format(budgetBean.getCostProjectManageTaxInclude()));
        Cell fifthCell = row.createCell(4);
        fifthCell.setCellStyle(style2);
        fifthCell.setCellType(CellType.NUMERIC);
        fifthCell.setCellValue(Utils.format(budgetBean.getCostProjectManageTaxExclude()));
    }

    private void createOtherRow(BudgetBean budgetBean, XSSFSheet sheet, int index, String otherName) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("成本");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("其他");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.STRING);
        thirdCell.setCellValue(otherName);
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style2);
        fourthCell.setCellType(CellType.NUMERIC);
        fourthCell.setCellValue(Utils.format(budgetBean.getCostOtherOtherTaxInclude()));
        Cell fifthCell = row.createCell(4);
        fifthCell.setCellStyle(style2);
        fifthCell.setCellType(CellType.NUMERIC);
        fifthCell.setCellValue(Utils.format(budgetBean.getCostOtherOtherTaxExclude()));
    }

    private void createTotalCostRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("合计");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.STRING);
        thirdCell.setCellValue("");
        Cell fourthCell = row.createCell(3);
        fourthCell.setCellStyle(style2);
        fourthCell.setCellType(CellType.NUMERIC);
        fourthCell.setCellValue(Utils.format(budgetBean.getCostTotalTaxInclude()));
        Cell fifthCell = row.createCell(4);
        fifthCell.setCellStyle(style2);
        fifthCell.setCellType(CellType.NUMERIC);
        fifthCell.setCellValue(Utils.format(budgetBean.getCostTotalTaxExclude()));
    }

    private int createManageRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        createSubTitleManageRow(sheet, index++);
        createExpropriationRow(budgetBean, sheet, index++);
        createCompanyManageRow(budgetBean, sheet, index++);
        return index;
    }

    private void createSubTitleManageRow(XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("类别");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("费用项目");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style);
        thirdCell.setCellType(CellType.STRING);
        thirdCell.setCellValue("不含税金额(元)");
    }

    private void createExpropriationRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("财务费用");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("资金占用成本");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.NUMERIC);
        thirdCell.setCellValue(Utils.format(budgetBean.getCostExpropriationTaxExclude()));
    }

    private void createCompanyManageRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("公司管理费用");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("");
        Cell thirdCell = row.createCell(2);
        thirdCell.setCellStyle(style2);
        thirdCell.setCellType(CellType.NUMERIC);
        thirdCell.setCellValue(Utils.format(budgetBean.getCostCompanyManageTaxExclude()));
    }

    private int createProfitRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        createSubTitleProfitRow(sheet, index++);
        createGrossProfitRow(budgetBean, sheet, index++);
        createGrossProfitMarginRow(budgetBean, sheet, index++);
        createContributionProfitRow(budgetBean, sheet, index++);
        createContributionProfitRateRow(budgetBean, sheet, index++);
        return index;
    }

    private void createSubTitleProfitRow(XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("类别");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("");
    }

    private void createGrossProfitRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("项目毛利(元)");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(budgetBean.getProjectGrossProfit()));
    }

    private void createGrossProfitMarginRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("项目毛利率(%)");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(budgetBean.getProjectGrossProfitRate()));
    }

    private void createContributionProfitRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("项目贡献利润(元)");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(budgetBean.getProjectContributionProfit()));
    }

    private void createContributionProfitRateRow(BudgetBean budgetBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("项目贡献利润率(%)");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(budgetBean.getProjectContributionProfitRate()));
    }


    private int createCashFlowRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        createSubTitleCashFlowRow(sheet, index++);
        createSaleIncomeCashRow(cashFlowBean, sheet, index++);
        createTaxReturnRow(cashFlowBean, sheet, index++);
        createEarnestMoneyIncomeRow(cashFlowBean, sheet, index++);
        createPurchaseCostRow(cashFlowBean, sheet, index++);
        createTaxCostRow(cashFlowBean, sheet, index++);
        createEarnestMoneyCostRow(cashFlowBean, sheet, index++);
        createNetCashFlowRow(cashFlowBean, sheet, index++);
        createCashInflowFromInvestingActivitiesRow(cashFlowBean, sheet, index++);
        createCashOutflowFromInvestingActivitiesRow(cashFlowBean, sheet, index++);
        createNetCashFromInvestingActivitiesRow(cashFlowBean, sheet, index++);
        createFinancingCapitalInflowRow(cashFlowBean, sheet, index++);
        createFinancingCapitalOutflowRow(cashFlowBean, sheet, index++);
        createFinancingCapitalCashflowRow(cashFlowBean, sheet, index++);
        createNetIncreaseMonetaryFundsRow(cashFlowBean, sheet, index++);
        return index;
    }

    private void createSubTitleCashFlowRow(XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("类别");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("金额(元)");
    }

    private void createSaleIncomeCashRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("销售商品、提供劳务收到的现金");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(cashFlowBean.getSaleIncomeCash()));
    }

    private void createTaxReturnRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("收到的税费返还");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("/");
    }

    private void createEarnestMoneyIncomeRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("收到其他与经营活动有关的现金");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(cashFlowBean.getEarnestMoneyIncome()));
    }

    private void createPurchaseCostRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("购买商品、接受劳务支付的现金");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(cashFlowBean.getPurchaseCost()));
    }

    private void createTaxCostRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("支付的各项税费");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("/");
    }

    private void createEarnestMoneyCostRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("支付其他与经营活动有关的现金");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(cashFlowBean.getEarnestMoneyCost()));
    }

    private void createNetCashFlowRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("经营活动产生的现金流量净额");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(cashFlowBean.getNetCashFlow()));
    }

    private void createCashInflowFromInvestingActivitiesRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("投资活动现金流入");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("/");
    }

    private void createCashOutflowFromInvestingActivitiesRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("投资活动现金流出");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("/");
    }

    private void createNetCashFromInvestingActivitiesRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("投资活动产生的现金流量净额");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.STRING);
        secondCell.setCellValue("/");
    }

    private void createFinancingCapitalInflowRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("融资资金流入");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(cashFlowBean.getFinancingCapitalInflow()));
    }

    private void createFinancingCapitalOutflowRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("还款资金流出");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(cashFlowBean.getFinancingCapitalOutflow()));
    }

    private void createFinancingCapitalCashflowRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("筹资活动产生的现金流量净额");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(cashFlowBean.getFinancingCapitalCashflow()));
    }

    private void createNetIncreaseMonetaryFundsRow(CashFlowBean cashFlowBean, XSSFSheet sheet, int index) {
        Row row = sheet.createRow(index);
        Cell firstCell = row.createCell(0);
        firstCell.setCellStyle(style2);
        firstCell.setCellType(CellType.STRING);
        firstCell.setCellValue("货币资金净增加额");
        Cell secondCell = row.createCell(1);
        secondCell.setCellStyle(style2);
        secondCell.setCellType(CellType.NUMERIC);
        secondCell.setCellValue(Utils.format(cashFlowBean.getNetIncreaseMonetaryFunds()));
    }

    public void exportSettleExcel(BudgetBean budgetBean, CashFlowBean cashFlowBean, FormerBean formerBean, SettleBean settleBean, FormerBean currentBean, int rowIndex, String sheetName, ServletOutputStream outputStream, String otherName) {
        ExportSettleExcelUtils exportSettleExcelUtils = new ExportSettleExcelUtils();
        exportSettleExcelUtils.exportSettleExcel(budgetBean, cashFlowBean, formerBean, settleBean, currentBean, rowIndex, sheetName, outputStream, otherName, workbook, style, style2);
    }

    public void exportFinalExcel(BudgetBean budgetBean, CashFlowBean cashFlowBean, FormerBean settleBean, FinalBean finalBean, int rowIndex, String sheetName, ServletOutputStream outputStream, String otherName) {
        ExportFinalExcelUtils exportFinalExcelUtils = new ExportFinalExcelUtils();
        exportFinalExcelUtils.exportFinalExcel(budgetBean, cashFlowBean, settleBean, finalBean, rowIndex, sheetName, outputStream, otherName, workbook, style, style2);
    }

    public void end(OutputStream out) throws IOException {
        workbook.write(out);
        out.flush();
        workbook.close();
        out.close();
    }

    public void exportIncomeDetailExcel(String[] headers, String[] columns, Project project, BudgetBean budgetBean, List<ProjectBudgetIncomeDetail> budgetIncomeDetail, Integer incomeTotalAmount, String pattern, int rowIndex, String sheetName, ServletOutputStream outputStream) {
        // 遍历集合数据，产生数据行
        int index = rowIndex;
        XSSFSheet sheet = workbook.createSheet(sheetName);
        sheet.setDefaultColumnWidth((short)20);
        Font font3 = workbook.createFont();
        font3.setColor(HSSFColor.HSSFColorPredefined.BLUE.getIndex());
        Row title = sheet.createRow(index++);
        for (int i = 0; i < headers.length; i++) {
            Cell firstCell = title.createCell(i);
            firstCell.setCellStyle(style);
            firstCell.setCellType(CellType.STRING);
            firstCell.setCellValue(headers[i]);
        }
        for (int i = 0; i < budgetIncomeDetail.size(); i++) {
            ProjectBudgetIncomeDetail incomeDetail = budgetIncomeDetail.get(i);
            Row row = sheet.createRow(index++);
            for (int j = 0; j < headers.length; j++) {
                Cell secondCell = row.createCell(j);
                secondCell.setCellStyle(style2);
                Object value = ObjectKit.get(incomeDetail, columns[j]);
                if ("tempId".equals(columns[j])) {
                    value = i + 1;
                } else if ("type".equals(columns[j])) {
                    if ((Integer) value == 1) {
                        value = "设备类";
                    } else if ((Integer) value == 2) {
                        value = "工程类";
                    } else if ((Integer) value == 3) {
                        value = "服务类";
                    }
                }
                if (value == null) {
                    secondCell.setCellType(CellType.STRING);
                    secondCell.setCellValue("");
                } else {
                    if (value instanceof Integer) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue((int) value);
                    } else if (value instanceof Long) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue((long) value);
                    } else if (value instanceof Double) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue((double) value);
                    } else if (value instanceof BigDecimal) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue(Utils.format(((BigDecimal) value)));
                    } else if (value instanceof Date) {
                        secondCell.setCellType(CellType.STRING);
                        String date_str = DateKit.toStr((Date) value, pattern);
                        secondCell.setCellValue(date_str);
                    } else {
                        secondCell.setCellType(CellType.STRING);
                        secondCell.setCellValue(value.toString());
                    }
                }
            }
        }
        Row total = sheet.createRow(index);
        for (int i = 0; i < headers.length; i++) {
            Cell totalCell = total.createCell(i);
            totalCell.setCellStyle(style2);
            if (i == 0) {
                totalCell.setCellType(CellType.STRING);
                totalCell.setCellValue("总计");
            } else if (i == 4) {
                totalCell.setCellType(CellType.NUMERIC);
                totalCell.setCellValue(incomeTotalAmount);
            } else if (i == 7) {
                totalCell.setCellType(CellType.NUMERIC);
                totalCell.setCellValue(Utils.format(budgetBean.getIncomeTotalTaxInclude()));
            } else if (i == 8) {
                totalCell.setCellType(CellType.NUMERIC);
                totalCell.setCellValue(Utils.format(budgetBean.getIncomeTotalTaxExclude()));
            } else {
                totalCell.setCellType(CellType.STRING);
                totalCell.setCellValue("");
            }
        }
    }

    public void exportCostDetailExcel(String[] headers, String[] columns, Project project, BudgetBean budgetBean, List<ProjectBudgetCostDetail> budgetCostDetail, Integer costTotalAmount, Map<Integer, String> procurementMap, String pattern, int rowIndex, String sheetName, ServletOutputStream outputStream) {
        // 遍历集合数据，产生数据行
        int index = rowIndex;
        XSSFSheet sheet = workbook.createSheet(sheetName);
        sheet.setDefaultColumnWidth((short)20);
        Font font3 = workbook.createFont();
        font3.setColor(HSSFColor.HSSFColorPredefined.BLUE.getIndex());
        Row title = sheet.createRow(index++);
        for (int i = 0; i < headers.length; i++) {
            Cell firstCell = title.createCell(i);
            firstCell.setCellStyle(style);
            firstCell.setCellType(CellType.STRING);
            firstCell.setCellValue(headers[i]);
        }
        for (int i = 0; i < budgetCostDetail.size(); i++) {
            ProjectBudgetCostDetail costDetail = budgetCostDetail.get(i);
            Row row = sheet.createRow(index++);
            for (int j = 0; j < headers.length; j++) {
                Cell secondCell = row.createCell(j);
                secondCell.setCellStyle(style2);
                Object value = ObjectKit.get(costDetail, columns[j]);
                if ("tempId".equals(columns[j])) {
                    value = i + 1;
                } else if ("type".equals(columns[j])) {
                    if ((Integer) value == 1) {
                        value = "设备";
                    } else if ((Integer) value == 2) {
                        value = "施工";
                    } else if ((Integer) value == 3) {
                        value = "服务";
                    } else if ((Integer) value == 4) {
                        value = "其他";
                    }
                } else if ("category".equals(columns[j])) {
                    value = procurementMap.get(value);
                }
                if (value == null) {
                    secondCell.setCellType(CellType.STRING);
                    secondCell.setCellValue("");
                } else {
                    if (value instanceof Integer) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue((int) value);
                    } else if (value instanceof Long) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue((long) value);
                    } else if (value instanceof Double) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue((double) value);
                    } else if (value instanceof BigDecimal) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue(Utils.format(((BigDecimal) value)));
                    } else if (value instanceof Date) {
                        secondCell.setCellType(CellType.STRING);
                        String date_str = DateKit.toStr((Date) value, pattern);
                        secondCell.setCellValue(date_str);
                    } else {
                        secondCell.setCellType(CellType.STRING);
                        secondCell.setCellValue(value.toString());
                    }
                }
            }
        }
        Row total = sheet.createRow(index);
        for (int i = 0; i < headers.length; i++) {
            Cell totalCell = total.createCell(i);
            totalCell.setCellStyle(style2);
            if (i == 0) {
                totalCell.setCellType(CellType.STRING);
                totalCell.setCellValue("总计");
            } else if (i == 5) {
                totalCell.setCellType(CellType.NUMERIC);
                totalCell.setCellValue(costTotalAmount);
            } else if (i == 8) {
                totalCell.setCellType(CellType.NUMERIC);
                totalCell.setCellValue(Utils.format(budgetBean.getCostTotalTaxInclude()));
            } else if (i == 9) {
                totalCell.setCellType(CellType.NUMERIC);
                totalCell.setCellValue(Utils.format(budgetBean.getCostTotalTaxExclude()));
            } else {
                totalCell.setCellType(CellType.STRING);
                totalCell.setCellValue("");
            }
        }
    }

    public void exportCostManageDetailExcel(String[] headers, String[] columns, Project project, BudgetBean budgetBean, List<ProjectBudgetCostProjectManageDetail> budgetCostProjectManageDetail, Integer costProjectManageTotalAmount, String pattern, int rowIndex, String sheetName, ServletOutputStream outputStream) {
        // 遍历集合数据，产生数据行
        int index = rowIndex;
        XSSFSheet sheet = workbook.createSheet(sheetName);
        sheet.setDefaultColumnWidth((short)20);
        Font font3 = workbook.createFont();
        font3.setColor(HSSFColor.HSSFColorPredefined.BLUE.getIndex());
        Row title = sheet.createRow(index++);
        for (int i = 0; i < headers.length; i++) {
            Cell firstCell = title.createCell(i);
            firstCell.setCellStyle(style);
            firstCell.setCellType(CellType.STRING);
            firstCell.setCellValue(headers[i]);
        }
        for (int i = 0; i < budgetCostProjectManageDetail.size(); i++) {
            ProjectBudgetCostProjectManageDetail costManageDetail = budgetCostProjectManageDetail.get(i);
            Row row = sheet.createRow(index++);
            for (int j = 0; j < headers.length; j++) {
                Cell secondCell = row.createCell(j);
                secondCell.setCellStyle(style2);
                Object value = ObjectKit.get(costManageDetail, columns[j]);
                if ("tempId".equals(columns[j])) {
                    value = i + 1;
                } else if ("type".equals(columns[j])) {
                    if ((Integer) value == 1) {
                        value = "人工成本";
                    } else if ((Integer) value == 2) {
                        value = "业务费用";
                    } else if ((Integer) value == 3) {
                        value = "其他费用";
                    }
                }
                if (value == null) {
                    secondCell.setCellType(CellType.STRING);
                    secondCell.setCellValue("");
                } else {
                    if (value instanceof Integer) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue((int) value);
                    } else if (value instanceof Long) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue((long) value);
                    } else if (value instanceof Double) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue((double) value);
                    } else if (value instanceof BigDecimal) {
                        secondCell.setCellType(CellType.NUMERIC);
                        secondCell.setCellValue(Utils.format(((BigDecimal) value)));
                    } else if (value instanceof Date) {
                        secondCell.setCellType(CellType.STRING);
                        String date_str = DateKit.toStr((Date) value, pattern);
                        secondCell.setCellValue(date_str);
                    } else {
                        secondCell.setCellType(CellType.STRING);
                        secondCell.setCellValue(value.toString());
                    }
                }
            }
        }
        Row total = sheet.createRow(index);
        for (int i = 0; i < headers.length; i++) {
            Cell totalCell = total.createCell(i);
            totalCell.setCellStyle(style2);
            if (i == 0) {
                totalCell.setCellType(CellType.STRING);
                totalCell.setCellValue("总计");
            } else if (i == 5) {
                totalCell.setCellType(CellType.NUMERIC);
                totalCell.setCellValue(costProjectManageTotalAmount);
            } else if (i == 7) {
                totalCell.setCellType(CellType.NUMERIC);
                totalCell.setCellValue(Utils.format(budgetBean.getCostProjectManageTaxExclude()));
            } else {
                totalCell.setCellType(CellType.STRING);
                totalCell.setCellValue("");
            }
        }
    }

    public void exportPlanDetailExcel(String[] headers, String[] rows, Project project, BudgetBean budgetBean, List<ProjectBudgetPlanDetail> projectBudgetPlanDetails, ProjectBudgetPlanDetail projectBudgetPlanDetailTotal, String pattern, int rowIndex, String sheetName, ServletOutputStream outputStream) {
        // 遍历集合数据，产生数据行
        int index = rowIndex;
        XSSFSheet sheet = workbook.createSheet(sheetName);
        sheet.setDefaultColumnWidth((short)20);
        Font font3 = workbook.createFont();
        font3.setColor(HSSFColor.HSSFColorPredefined.BLUE.getIndex());
        for (int i = 0; i < rows.length; i++){
            Row row = sheet.createRow(index++);
            Cell firstCell = row.createCell(0);
            firstCell.setCellStyle(style);
            firstCell.setCellType(CellType.STRING);
            firstCell.setCellValue(headers[i]);
            Cell secondCell = row.createCell(1);
            secondCell.setCellStyle(style2);
            Object value = ObjectKit.get(projectBudgetPlanDetailTotal, rows[i]);
            if (i == 0) {
                value = "合计";
            }
            if(value == null){
                secondCell.setCellType(CellType.STRING);
                secondCell.setCellValue("");
            }else{
                if(value instanceof Integer){
                    secondCell.setCellType(CellType.NUMERIC);
                    secondCell.setCellValue((int)value);
                } else if(value instanceof Long){
                    secondCell.setCellType(CellType.NUMERIC);
                    secondCell.setCellValue((long)value);
                } else if(value instanceof Double){
                    secondCell.setCellType(CellType.NUMERIC);
                    secondCell.setCellValue((double)value);
                } else if(value instanceof BigDecimal){
                    secondCell.setCellType(CellType.NUMERIC);
                    secondCell.setCellValue(Utils.format(((BigDecimal)value)));
                } else if(value instanceof Date){
                    secondCell.setCellType(CellType.STRING);
                    String date_str = DateKit.toStr((Date) value, pattern);
                    secondCell.setCellValue(date_str);
                } else{
                    secondCell.setCellType(CellType.STRING);
                    secondCell.setCellValue(value.toString());
                }
            }
            for (int j = 0; j < projectBudgetPlanDetails.size(); j++) {
                Cell nextCell = row.createCell(j + 2);
                nextCell.setCellStyle(style2);
                Object value2 = ObjectKit.get(projectBudgetPlanDetails.get(j), rows[i]);
                if(value == null){
                    nextCell.setCellType(CellType.STRING);
                    nextCell.setCellValue("");
                }else{
                    if(value instanceof Integer){
                        nextCell.setCellType(CellType.NUMERIC);
                        nextCell.setCellValue((int)value2);
                    } else if(value instanceof Long){
                        nextCell.setCellType(CellType.NUMERIC);
                        nextCell.setCellValue((long)value2);
                    } else if(value instanceof Double){
                        nextCell.setCellType(CellType.NUMERIC);
                        nextCell.setCellValue((double)value2);
                    } else if(value instanceof BigDecimal){
                        nextCell.setCellType(CellType.NUMERIC);
                        nextCell.setCellValue(Utils.format(((BigDecimal)value2)));
                    } else if(value instanceof Date){
                        nextCell.setCellType(CellType.STRING);
                        String date_str = DateKit.toStr((Date) value2, pattern);
                        nextCell.setCellValue(date_str);
                    } else{
                        nextCell.setCellType(CellType.STRING);
                        nextCell.setCellValue(value2.toString());
                    }
                }
            }
        }
    }
}
