使用poi3.13和spire.doc.free2.7.3生成的word完整代码,包含生成word表格,生成多级标题,生成目录,生成页脚页码

package com.chuangqi.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chuangqi.entity.*;
import com.chuangqi.mapper.ExperimentDesignMapper;
import com.chuangqi.mapper.IndexEvaluationMissionMapper;
import com.chuangqi.mapper.IndexEvaluationModelMapper;
import com.chuangqi.mapper.ProjectMapper;
import com.chuangqi.service.*;
import com.chuangqi.tools.DownloadUtils;
import com.cq.cloudsim.simtaskinfo.ExperimentDesignSpace.DesignSchemeSpaceProcesser;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.documents.HorizontalAlignment;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.TableOfContent;
import com.spire.doc.fields.TextRange;
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.impl.xb.xmlschema.SpaceAttribute;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import com.spire.doc.Document;


/**
 * \* Created with IntelliJ IDEA.
 * \* @author: xiyue
 * \* Date: 2020/3/17
 * \* Time: 9:07
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
@Service
public class WordServiceImpl implements WordService {

    @Autowired
    private ProjectMapper projectMapper;

    @Autowired
    private DataService dataService;

    @Autowired
    private LogEvaluationService logEvaluationService;

    @Autowired
    private ModelService modelService;

    @Autowired
    private MethodService methodService;

    @Autowired
    private IndexEvaluationMissionMapper indexEvaluationMissionMapper;

    @Autowired
    private EquipmentTypeService equipmentTypeService;

    @Autowired
    private SecurityLevelService securityLevelService;

    @Autowired
    private IndexEvaluationModelMapper indexEvaluationModelMapper;

    @Autowired
    private ExperimentDesignMapper experimentDesignMapper;

    @Autowired
    private EquipmentCategoryService equipmentCategoryService;

    @Autowired
    private UserService userService;

    @Autowired
    private IndexService indexService;


    @Override
    public void ExportInterpretationSignsWordById(Integer id, HttpServletResponse response, HttpServletRequest request) throws IOException {
        final Integer modelId = 64;

        //获取工程
        Project project = projectMapper.selectByPrimaryKey(id);


        //日期转为字符串
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日EEEE");
        String createTime = simpleDateFormat.format(new Date());


        //创建文档对象
        XWPFDocument document = new XWPFDocument();

        addCustomHeadingStyle(document, "标题 1", 1);
        addCustomHeadingStyle(document, "标题 2", 2);
        addCustomHeadingStyle(document, "标题 3", 3);
        //创建项目编号
        XWPFParagraph titleParagraphXMBH = document.createParagraph();



        /*
         * 生成页脚段落
         * 给段落设置宽度为占满一行
         * */
        CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
        XWPFHeaderFooterPolicy headerFooterPolicy = new XWPFHeaderFooterPolicy(document, sectPr);
        XWPFFooter footer = headerFooterPolicy.createFooter(STHdrFtr.DEFAULT);
        System.out.println(footer);
        List<XWPFParagraph> paragraphs = footer.getParagraphs();
        System.out.println(paragraphs);
        XWPFParagraph paragraph = footer.getParagraphArray(0);
        System.out.println(paragraph);
        paragraph.setAlignment(ParagraphAlignment.CENTER);
        paragraph.setVerticalAlignment(TextAlignment.CENTER);
        paragraph.setBorderTop(Borders.THICK);
        CTTabStop tabStop = paragraph.getCTP().getPPr().addNewTabs().addNewTab();
        tabStop.setVal(STTabJc.RIGHT);
        int twipsPerInch = 1440;
        tabStop.setPos(BigInteger.valueOf(6 * twipsPerInch));
        /*
         * 给段落创建元素
         * 设置元素字面为公司地址+公司电话
         * */
        XWPFRun run = paragraph.createRun();
        setXWPFRunStyle(run, "宋体", 8);
        run.addTab();
//        String s=run.getFontFamily();
        /*
         * 生成页码
         * 页码右对齐
         * */
        run = paragraph.createRun();
        run.setText("第");
        setXWPFRunStyle(run, "宋体", 8);
        run = paragraph.createRun();
        CTFldChar fldChar = run.getCTR().addNewFldChar();
        fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));
        setXWPFRunStyle(run, "宋体", 8);
        run = paragraph.createRun();
        CTText ctText = run.getCTR().addNewInstrText();
        ctText.setStringValue("PAGE  \\* MERGEFORMAT");
        ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
        setXWPFRunStyle(run, "宋体", 8);

        fldChar = run.getCTR().addNewFldChar();
        fldChar.setFldCharType(STFldCharType.Enum.forString("end"));

        run = paragraph.createRun();
        run.setText("页/共");
        setXWPFRunStyle(run, "宋体", 8);

        run = paragraph.createRun();
        fldChar = run.getCTR().addNewFldChar();
        fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));

        run = paragraph.createRun();
        ctText = run.getCTR().addNewInstrText();
        ctText.setStringValue("NUMPAGES  \\* MERGEFORMAT ");
        ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
        setXWPFRunStyle(run, "宋体", 8);

        fldChar = run.getCTR().addNewFldChar();
        fldChar.setFldCharType(STFldCharType.Enum.forString("end"));

        run = paragraph.createRun();
        run.setText("页");
        setXWPFRunStyle(run, "宋体", 8);


        titleParagraphXMBH.setAlignment(ParagraphAlignment.LEFT);
        XWPFRun titleParagraphXMBHRun = titleParagraphXMBH.createRun();
        titleParagraphXMBHRun.setText("项目编号____________                         密级__________");
        titleParagraphXMBHRun.setFontFamily("宋体");
        titleParagraphXMBHRun.setColor("000000");
        titleParagraphXMBHRun.setFontSize(14);
        for (int i = 0; i < 4; i++) {
            titleParagraphXMBHRun.addCarriageReturn();
        }


        //创建段落对象
        XWPFParagraph titleParagraph = document.createParagraph();
        //设置段落居中
        titleParagraph.setAlignment(ParagraphAlignment.CENTER);
        //创建文本对象,主角
        XWPFRun titleParagraphRun = titleParagraph.createRun();
        //创建大标题文本
        titleParagraphRun.setText("验 证 报 告");
        //设置加粗
        titleParagraphRun.setBold(false);
        //设置大标题字体
        titleParagraphRun.setFontFamily("黑体");
        //设置大标题字体颜色
        titleParagraphRun.setColor("000000");
        //设置大标题字体大小
        titleParagraphRun.setFontSize(22);


        XWPFParagraph titleParagraphKG = document.createParagraph();
        titleParagraphKG.setAlignment(ParagraphAlignment.LEFT);
        XWPFRun titleParagraphKGRun = titleParagraphKG.createRun();
        titleParagraphKGRun.setText("");
        titleParagraphKGRun.setFontFamily("宋体");
        titleParagraphKGRun.setColor("000000");
        titleParagraphKGRun.setFontSize(14);
        for (int i = 0; i < 3; i++) {
            //换行
            titleParagraphKGRun.addCarriageReturn();
        }

        //创建大标题下的段落1
        XWPFParagraph firstParagraph = document.createParagraph();
        //设置段落居中
        firstParagraph.setAlignment(ParagraphAlignment.CENTER);
        //创建大标题下的段落文本对象1
        XWPFRun firstParagraphRun = firstParagraph.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun.setText("项目名称:");
        //设置大标题字体颜色
        firstParagraphRun.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun.setFontSize(16);
        //设置字体
        firstParagraphRun.setFontFamily("宋体");

        XWPFRun firstParagraphRun1 = firstParagraph.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun1.setText(project.getName());
        firstParagraphRun1.setUnderline(UnderlinePatterns.SINGLE);
        //设置大标题字体颜色
        firstParagraphRun1.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun1.setFontSize(16);
        //设置字体
        firstParagraphRun1.setFontFamily("宋体");


        //创建大标题下的段落1
        XWPFParagraph firstParagraph2 = document.createParagraph();
        //设置段落居中
        firstParagraph2.setAlignment(ParagraphAlignment.CENTER);
        //创建大标题下的段落文本对象1
        XWPFRun firstParagraphRun21 = firstParagraph2.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun21.setText("报告版本:");
        //设置大标题字体颜色
        firstParagraphRun21.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun21.setFontSize(16);
        //设置字体
        firstParagraphRun21.setFontFamily("宋体");

        XWPFRun firstParagraphRun22 = firstParagraph2.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun22.setText("第一版本");
        firstParagraphRun22.setUnderline(UnderlinePatterns.SINGLE);
        //设置大标题字体颜色
        firstParagraphRun22.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun22.setFontSize(16);
        //设置字体
        firstParagraphRun22.setFontFamily("宋体");

        //创建大标题下的段落1
        XWPFParagraph firstParagraph3 = document.createParagraph();
        //设置段落居中
        firstParagraph3.setAlignment(ParagraphAlignment.CENTER);
        //创建大标题下的段落文本对象1
        XWPFRun firstParagraphRun31 = firstParagraph3.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun31.setText("负责人:");
        //设置大标题字体颜色
        firstParagraphRun31.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun31.setFontSize(16);
        //设置字体
        firstParagraphRun31.setFontFamily("宋体");

        XWPFRun firstParagraphRun32 = firstParagraph3.createRun();
        //设置大标题下的段落文本1
        Integer creatorId = project.getCreatorId();
        User user = userService.selectByPrimaryKey(creatorId);
        firstParagraphRun32.setText(user.getName());
        firstParagraphRun32.setUnderline(UnderlinePatterns.SINGLE);
        //设置大标题字体颜色
        firstParagraphRun32.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun32.setFontSize(16);
        //设置字体
        firstParagraphRun32.setFontFamily("宋体");

        //创建大标题下的段落1
        XWPFParagraph firstParagraph4 = document.createParagraph();
        //设置段落居中
        firstParagraph4.setAlignment(ParagraphAlignment.CENTER);
        //创建大标题下的段落文本对象1
        XWPFRun firstParagraphRun41 = firstParagraph4.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun41.setText("编制:");
        //设置大标题字体颜色
        firstParagraphRun41.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun41.setFontSize(16);
        //设置字体
        firstParagraphRun41.setFontFamily("宋体");

        XWPFRun firstParagraphRun42 = firstParagraph4.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun42.setText("啦啦啦");
        firstParagraphRun42.setUnderline(UnderlinePatterns.SINGLE);
        //设置大标题字体颜色
        firstParagraphRun42.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun42.setFontSize(16);
        //设置字体
        firstParagraphRun42.setFontFamily("宋体");


        //创建大标题下的段落1
        XWPFParagraph firstParagraph5 = document.createParagraph();
        //设置段落居中
        firstParagraph5.setAlignment(ParagraphAlignment.CENTER);
        //创建大标题下的段落文本对象1
        XWPFRun firstParagraphRun51 = firstParagraph5.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun51.setText("校对:");
        //设置大标题字体颜色
        firstParagraphRun51.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun51.setFontSize(16);
        //设置字体
        firstParagraphRun51.setFontFamily("宋体");

        XWPFRun firstParagraphRun52 = firstParagraph5.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun52.setText("聚聚聚");
        firstParagraphRun52.setUnderline(UnderlinePatterns.SINGLE);
        //设置大标题字体颜色
        firstParagraphRun52.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun52.setFontSize(16);
        //设置字体
        firstParagraphRun52.setFontFamily("宋体");


        //创建大标题下的段落1
        XWPFParagraph firstParagraph6 = document.createParagraph();
        //设置段落居中
        firstParagraph6.setAlignment(ParagraphAlignment.CENTER);
        //创建大标题下的段落文本对象1
        XWPFRun firstParagraphRun61 = firstParagraph6.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun61.setText("审查:");
        //设置大标题字体颜色
        firstParagraphRun61.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun61.setFontSize(16);
        //设置字体
        firstParagraphRun61.setFontFamily("宋体");

        XWPFRun firstParagraphRun62 = firstParagraph6.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun62.setText("与玉玉");
        firstParagraphRun62.setUnderline(UnderlinePatterns.SINGLE);
        //设置大标题字体颜色
        firstParagraphRun62.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun62.setFontSize(16);
        //设置字体
        firstParagraphRun62.setFontFamily("宋体");


        //创建大标题下的段落1
        XWPFParagraph firstParagraph7 = document.createParagraph();
        //设置段落居中
        firstParagraph7.setAlignment(ParagraphAlignment.CENTER);
        //创建大标题下的段落文本对象1
        XWPFRun firstParagraphRun71 = firstParagraph7.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun71.setText("会签:");
        //设置大标题字体颜色
        firstParagraphRun71.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun71.setFontSize(16);
        //设置字体
        firstParagraphRun71.setFontFamily("宋体");

        XWPFRun firstParagraphRun72 = firstParagraph7.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun72.setText("图图图");
        firstParagraphRun72.setUnderline(UnderlinePatterns.SINGLE);
        //设置大标题字体颜色
        firstParagraphRun72.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun72.setFontSize(16);
        //设置字体
        firstParagraphRun72.setFontFamily("宋体");


        //创建大标题下的段落1
        XWPFParagraph firstParagraph8 = document.createParagraph();
        //设置段落居中
        firstParagraph8.setAlignment(ParagraphAlignment.CENTER);
        //创建大标题下的段落文本对象1
        XWPFRun firstParagraphRun81 = firstParagraph8.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun81.setText("批准:");
        //设置大标题字体颜色
        firstParagraphRun81.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun81.setFontSize(16);
        //设置字体
        firstParagraphRun81.setFontFamily("宋体");

        XWPFRun firstParagraphRun82 = firstParagraph8.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun82.setText("嘟嘟嘟");
        firstParagraphRun82.setUnderline(UnderlinePatterns.SINGLE);
        //设置大标题字体颜色
        firstParagraphRun82.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun82.setFontSize(16);
        //设置字体
        firstParagraphRun82.setFontFamily("宋体");


        //创建大标题下的段落1
        XWPFParagraph firstParagraph9 = document.createParagraph();
        //设置段落居中
        firstParagraph9.setAlignment(ParagraphAlignment.CENTER);
        //创建大标题下的段落文本对象1
        XWPFRun firstParagraphRun91 = firstParagraph9.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun91.setText("完成单位:");
        //设置大标题字体颜色
        firstParagraphRun91.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun91.setFontSize(16);
        //设置字体
        firstParagraphRun91.setFontFamily("宋体");

        XWPFRun firstParagraphRun92 = firstParagraph9.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun92.setText("我我欧");
        firstParagraphRun92.setUnderline(UnderlinePatterns.SINGLE);
        //设置大标题字体颜色
        firstParagraphRun92.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun92.setFontSize(16);
        //设置字体
        firstParagraphRun92.setFontFamily("宋体");

        //创建大标题下的段落1
        XWPFParagraph firstParagraph10 = document.createParagraph();
        //设置段落居中
        firstParagraph10.setAlignment(ParagraphAlignment.CENTER);
        //创建大标题下的段落文本对象1
        XWPFRun firstParagraphRun101 = firstParagraph10.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun101.setText("完成日期:");
        //设置大标题字体颜色
        firstParagraphRun101.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun101.setFontSize(16);
        //设置字体
        firstParagraphRun101.setFontFamily("宋体");

        XWPFRun firstParagraphRun102 = firstParagraph10.createRun();
        //设置大标题下的段落文本1
        firstParagraphRun102.setText("服服服");
        firstParagraphRun102.setUnderline(UnderlinePatterns.SINGLE);
        //设置大标题字体颜色
        firstParagraphRun102.setColor("000000");
        //设置大标题字体大小
        firstParagraphRun102.setFontSize(16);
        //设置字体
        firstParagraphRun102.setFontFamily("宋体");

//        firstParagraphRun102.addCarriageReturn();
//        firstParagraphRun102.addCarriageReturn();
//        firstParagraphRun102.addCarriageReturn();


        //换页
        XWPFParagraph page0 = document.createParagraph();
        //给这个段落添加一个分隔符即可。
        page0.setPageBreak(true);


        //创建大标题下的段落2的开头
        XWPFParagraph secondParagraph = document.createParagraph();
        //设置段落居中
        secondParagraph.setAlignment(ParagraphAlignment.CENTER);
        //创建大标题下的段落文本对象2的开头
        XWPFRun secondParagraphRun = secondParagraph.createRun();
        //设置大标题下的段落文本2的开头
        secondParagraphRun.setText("版本变更情况");
        //设置大标题字体颜色
        secondParagraphRun.setColor("000000");
        //设置大标题字体大小
        secondParagraphRun.setFontSize(22);
        //设置字体
        secondParagraphRun.setFontFamily("黑体");


        //创建试验设计表格
        XWPFTable tableBanBen = document.createTable();

        //设置表级别单元格边距
        tableBanBen.setCellMargins(13, 5, 353, 5);
        //列宽自动分割
        CTTblWidth tableBanBenWidth = tableBanBen.getCTTbl().addNewTblPr().addNewTblW();

        tableBanBenWidth.setType(STTblWidth.DXA);
        tableBanBenWidth.setW(BigInteger.valueOf(9972));


        //创建试验设计标题数组
        String[] titleBanBen = new String[]{"序号", "版本号", "版本问题", "变更内容", "描述", "审核人"};

        for (int i = 0; i < 12; i++) {
            if (i == 0) {
                XWPFTableRow tableBanBenRowOne = tableBanBen.getRow(i);

                XWPFTableCell xwpfTableCell0 = tableBanBenRowOne.getCell(0);
                //水平居中
                XWPFParagraph xwpfParagraph0 = xwpfTableCell0.addParagraph();
                //垂直居中
                xwpfParagraph0.setAlignment(ParagraphAlignment.CENTER);
                //水平居中
                xwpfParagraph0.setVerticalAlignment(TextAlignment.CENTER);
                XWPFRun run0 = xwpfParagraph0.createRun();
                run0.setText(titleBanBen[0]);
                run0.setFontSize(12);
                run0.setBold(true);
                for (int j = 1; j < 6; j++) {
                    XWPFTableCell xwpfTableCell1 = tableBanBenRowOne.addNewTableCell();
                    //水平居中
                    XWPFParagraph xwpfParagraph1 = xwpfTableCell1.addParagraph();
                    //垂直居中
                    xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                    //水平居中
                    xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                    XWPFRun run1 = xwpfParagraph1.createRun();
                    run1.setText(titleBanBen[j]);
                    run1.setFontSize(12);
                    run1.setBold(true);
                    run1.setFontFamily("宋体");
                }
            } else {

                XWPFTableRow tableBanBenRowOne = tableBanBen.createRow();
                for (int j = 0; j < 6; j++) {
                    XWPFTableCell xwpfTableCell1 = tableBanBenRowOne.getCell(j);
                    //水平居中
                    XWPFParagraph xwpfParagraph1 = xwpfTableCell1.addParagraph();
                    //垂直居中
                    xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                    //水平居中
                    xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                    XWPFRun run1 = xwpfParagraph1.createRun();
                    run1.setText("");
                    run1.setFontSize(12);
                    run1.setBold(false);
                    run1.setFontFamily("宋体");
                }
            }

        }

        //换页
        XWPFParagraph page1 = document.createParagraph();
        //给这个段落添加一个分隔符即可。
        page1.setPageBreak(true);


        //创建小标题1摘要
        XWPFParagraph firstTitleParagraph = document.createParagraph();
        //创建小标题的段落文本对象的文本
        XWPFRun firstTitleParagraphRun = firstTitleParagraph.createRun();
        //设置小标题下的段落文本的文本
        firstTitleParagraphRun.setText("摘  要");
        //设置段落居中
        firstTitleParagraph.setAlignment(ParagraphAlignment.CENTER);
        //设置大标题字体颜色
        firstTitleParagraphRun.setColor("000000");
        //设置大标题字体大小
        firstTitleParagraphRun.setFontSize(22);
        //设置字体格式
        firstTitleParagraphRun.setFontFamily("华文中宋");
        //设置加粗
        firstTitleParagraphRun.setBold(false);


        //创建小标题1摘要下的文本
        XWPFParagraph firstTitleContentParagraph = document.createParagraph();
        //设置首行缩进
        firstTitleContentParagraph.setIndentationFirstLine(2);
        //创建小标题1下的文本的段落文本对象的文本
        XWPFRun firstTitleContentParagraphRun = firstTitleContentParagraph.createRun();
        //创建小标题1下的文本
        firstTitleContentParagraphRun.setText("    cpu通过时间片循环执行线程任务,当线程的cpu时间片用完后会保存当前任务状态,方便下次获取到cpu时间片的时候能继续执行,当下次分配时间片后执行到该线程时,会重新加载该线程的任务状态,而这个从保存任务状态到重新加载的过程就叫上下文换。每次上下文切换也都要消耗cpu资源的,就好比看英文书一样,你边英文看边去看翻译,在你看翻译之前你必须要记住当前英文书看到了第几页,这样的切换是会影响读书的效率,同样上下文切换也会影响多线程的执行速度。");
        //设置小标题1下的文本字体颜色
        firstTitleContentParagraphRun.setColor("000000");
        //设置小标题1下的文本字体大小
        firstTitleContentParagraphRun.setFontSize(12);
        //设置字体格式
        firstTitleContentParagraphRun.setFontFamily("宋体");


        //换页
        XWPFParagraph page2 = document.createParagraph();
        //给这个段落添加一个分隔符即可。
        page2.setPageBreak(true);
        //换页
        XWPFParagraph page3 = document.createParagraph();
        //给这个段落添加一个分隔符即可。
        page3.setPageBreak(true);

        //一级标题
        int biaoTi1 = 1;


        //创建一级标题    项目名称
        XWPFParagraph secondTitleParagraph = document.createParagraph();
        //关键行   一级标题
        secondTitleParagraph.setStyle("标题 1");
        //创建小标题2的段落文本对象的文本
        XWPFRun secondTitleParagraphRun = secondTitleParagraph.createRun();
        //设置小标题2下的段落文本的文本
        secondTitleParagraphRun.setText("1 项目名称");
        //设置小标题2字体颜色
        secondTitleParagraphRun.setColor("000000");
        //设置大标题字体大小
        secondTitleParagraphRun.setFontSize(18);
        //设置字体格式
        secondTitleParagraphRun.setFontFamily("黑体");
        //设置加粗
        secondTitleParagraphRun.setBold(false);

        //创建一级标题标题下的文本
        XWPFParagraph secondTitleContentParagraph = document.createParagraph();
        //设置首行缩进
        secondTitleContentParagraph.setIndentationFirstLine(2);
        //创建小标题2下的文本的段落文本对象的文本
        XWPFRun secondTitleContentParagraphRun = secondTitleContentParagraph.createRun();
        //创建小标题2下的文本
        secondTitleContentParagraphRun.setText(project.getName() + "工程");
        //设置小标题2下的文本字体颜色
        secondTitleContentParagraphRun.setColor("000000");
        //设置小标题2下的文本字体大小
        secondTitleContentParagraphRun.setFontSize(12);
        //设置字体格式
        secondTitleContentParagraphRun.setFontFamily("宋体");

        //创建一级标题    项目目的
        XWPFParagraph thirdTitleParagraph = document.createParagraph();
        //关键行   一级标题
        thirdTitleParagraph.setStyle("标题 1");
        //创建小标题3的段落文本对象的文本
        XWPFRun thirdTitleParagraphRun = thirdTitleParagraph.createRun();
        //设置小标题3下的段落文本的文本
        thirdTitleParagraphRun.setText("2 项目目的");
        //设置小标题3字体颜色
        thirdTitleParagraphRun.setColor("000000");
        //设置大标题字体大小
        thirdTitleParagraphRun.setFontSize(18);
        //设置字体格式
        thirdTitleParagraphRun.setFontFamily("黑体");
        //设置加粗
        thirdTitleParagraphRun.setBold(false);

        //创建一级标题标题3下的文本
        XWPFParagraph thirdTitleContentParagraph = document.createParagraph();
        //设置首行缩进
        thirdTitleContentParagraph.setIndentationFirstLine(2);
        //创建小标题3下的文本的段落文本对象的文本
        XWPFRun thirdTitleContentParagraphRun = thirdTitleContentParagraph.createRun();
        //创建小标题3下的文本
        thirdTitleContentParagraphRun.setText(project.getPurpose());
        //设置小标题3下的文本字体颜色
        thirdTitleContentParagraphRun.setColor("000000");
        //设置小标题3下的文本字体大小
        thirdTitleContentParagraphRun.setFontSize(12);
        //设置字体格式
        thirdTitleContentParagraphRun.setFontFamily("宋体");

        //创建一级标题    活动日期
        XWPFParagraph fourthTitleParagraph = document.createParagraph();
        //关键行   一级标题
        fourthTitleParagraph.setStyle("标题 1");
        //创建小标题4的段落文本对象的文本
        XWPFRun fourthTitleParagraphRun = fourthTitleParagraph.createRun();
        //设置小标题4下的段落文本的文本
        fourthTitleParagraphRun.setText("3 活动日期");
        //设置小标题4字体颜色
        fourthTitleParagraphRun.setColor("000000");
        //设置大标题字体大小
        fourthTitleParagraphRun.setFontSize(18);
        //设置字体格式
        fourthTitleParagraphRun.setFontFamily("黑体");
        //设置加粗
        fourthTitleParagraphRun.setBold(false);


        //创建一级标题3下的文本
        XWPFParagraph fourthTitleContentParagraph = document.createParagraph();
        //设置首行缩进
        fourthTitleContentParagraph.setIndentationFirstLine(4);
        //创建小标题3下的文本的段落文本对象的文本
        XWPFRun fourthTitleContentParagraphRun = fourthTitleContentParagraph.createRun();
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyy年MM月dd日");
        Date createTime1 = project.getCreateTime();
        Date actualFinishTime = project.getActualFinishTime();
        String format = simpleDateFormat1.format(createTime1);
        String format1 = simpleDateFormat1.format(actualFinishTime);
        //创建小标题3下的文本
        fourthTitleContentParagraphRun.setText(format + "-" + format1);
        //设置小标题3下的文本字体颜色
        fourthTitleContentParagraphRun.setColor("000000");
        //设置小标题3下的文本字体大小
        fourthTitleContentParagraphRun.setFontSize(12);
        //设置字体格式
        fourthTitleContentParagraphRun.setFontFamily("宋体");

        XWPFParagraph fourthTitleContentParagraphOne = document.createParagraph();
        //关键行   一级标题
        fourthTitleContentParagraphOne.setStyle("标题 1");
        XWPFRun fourthTitleContentParagraphRunOne = fourthTitleContentParagraphOne.createRun();
        fourthTitleContentParagraphRunOne.setText("4 人员分工");
        fourthTitleContentParagraphRunOne.setColor("000000");
        fourthTitleContentParagraphRunOne.setFontSize(18);
        fourthTitleContentParagraphRunOne.setFontFamily("黑体");


        //创建人员分工表格
        XWPFTable tableUser = document.createTable();
        //设置表级别单元格边距
        tableUser.setCellMargins(3, 5, 253, 5);
        //列宽自动分割
        CTTblWidth tableUserWidth = tableUser.getCTTbl().addNewTblPr().addNewTblW();
        tableUserWidth.setType(STTblWidth.DXA);
        tableUserWidth.setW(BigInteger.valueOf(9972));


        //创建人员标题数组
        String[] titleUser = new String[]{"姓名", "单位", "职务", "联系方式"};

        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                XWPFTableRow tableUserRowOne = tableUser.getRow(i);

                XWPFTableCell xwpfTableCell0 = tableUserRowOne.getCell(0);
                //水平居中
                XWPFParagraph xwpfParagraph0 = xwpfTableCell0.addParagraph();
                //垂直居中
                xwpfParagraph0.setAlignment(ParagraphAlignment.CENTER);
                //水平居中
                xwpfParagraph0.setVerticalAlignment(TextAlignment.CENTER);
                XWPFRun run0 = xwpfParagraph0.createRun();
                run0.setText(titleUser[0]);
                run0.setFontSize(12);
                run0.setBold(true);
                run0.setFontFamily("宋体");
                for (int j = 1; j < titleUser.length; j++) {
                    XWPFTableCell xwpfTableCell1 = tableUserRowOne.addNewTableCell();
                    //水平居中
                    XWPFParagraph xwpfParagraph1 = xwpfTableCell1.addParagraph();
                    //垂直居中
                    xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                    //水平居中
                    xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                    XWPFRun run1 = xwpfParagraph1.createRun();
                    run1.setText(titleUser[j]);
                    run1.setFontSize(12);
                    run1.setBold(true);
                    run1.setFontFamily("宋体");
                }
            } else {
                String[] titleUserInfo = new String[]{user.getName(), user.getPassword(), user.getRole(), user.getEquipment()};
                XWPFTableRow tableUserRowOne = tableUser.createRow();
                for (int j = 0; j < titleUser.length; j++) {
                    XWPFTableCell xwpfTableCell1 = tableUserRowOne.getCell(j);
                    //水平居中
                    XWPFParagraph xwpfParagraph1 = xwpfTableCell1.addParagraph();
                    //垂直居中
                    xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                    //水平居中
                    xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                    XWPFRun run1 = xwpfParagraph1.createRun();
                    run1.setText(titleUserInfo[j]);
                    run1.setFontSize(12);
                    run1.setBold(false);
                    run1.setFontFamily("宋体");
                }
            }

        }


        //创建一级标题5
        XWPFParagraph fifthTitleParagraph = document.createParagraph();
        //关键设置一级标题
        fifthTitleParagraph.setStyle("标题 1");
        //创建小标题5的段落文本对象的文本
        XWPFRun fifthTitleParagraphRun = fifthTitleParagraph.createRun();
        //设置小标题5下的段落文本的文本
        fifthTitleParagraphRun.setText("5 模型描述");
        //设置小标题5字体颜色
        fifthTitleParagraphRun.setColor("000000");
        //设置大标题字体大小
        fifthTitleParagraphRun.setFontSize(18);
        //设置字体格式
        fifthTitleParagraphRun.setFontFamily("黑体");
        //设置加粗
        fifthTitleParagraphRun.setBold(false);

        String t = "    ";
        Model model = modelService.selectByPrimaryKey(modelId);
        Integer levelId = model.getLevelId();
        String levelName = securityLevelService.selectByPrimaryKey(levelId).getName();
        Integer equipmentTypeId = model.getEquipmentTypeId();
        EquipmentType equipmentType = equipmentTypeService.selectByPrimaryKey(equipmentTypeId);
        String equipmentTypeName = equipmentType.getName();
        Integer categoryId = equipmentType.getCategoryId();
        String equipmentCategoryName = equipmentCategoryService.selectByPrimaryKey(categoryId).getName();
        String[] modelInfo = new String[]{
                "模型名称:" + model.getName(),
                "保密等级:" + levelName,
                "模型编号:" + model.getId(),
                "模型版本:" + model.getVersion(),
                "装备型号:" + equipmentTypeName,
                "装备类型:" + equipmentCategoryName,
                "模型备注:" + model.getDescription()
        };
        for (int i = 0; i < modelInfo.length; i++) {
            //创建一级标题5下的文本
            XWPFParagraph fifthTitleContentParagraph = document.createParagraph();
            //设置首行缩进
            fifthTitleContentParagraph.setIndentationFirstLine(2);
            //创建小标题5下的文本的段落文本对象的文本
            XWPFRun fifthTitleContentParagraphRun = fifthTitleContentParagraph.createRun();
            //创建小标题5下的文本
            fifthTitleContentParagraphRun.setText(t + modelInfo[i]);
            //设置小标题5下的文本字体颜色
            fifthTitleContentParagraphRun.setColor("000000");
            //设置小标题5下的文本字体大小
            fifthTitleContentParagraphRun.setFontSize(12);
            //设置字体格式
            fifthTitleContentParagraphRun.setFontFamily("宋体");
        }


        //一级标题指标体系
        XWPFParagraph fifthTitleContentParagraphOne = document.createParagraph();
        fifthTitleContentParagraphOne.setStyle("标题 1");
        XWPFRun fifthTitleContentParagraphRunOne = fifthTitleContentParagraphOne.createRun();
        fifthTitleContentParagraphRunOne.setText("6 指标体系");
        fifthTitleContentParagraphRunOne.setColor("000000");
        fifthTitleContentParagraphRunOne.setFontSize(18);
        fifthTitleContentParagraphRunOne.setFontFamily("黑体");


        Integer indexSystemId = project.getIndexSystemId();
        //根据指标体系id来查询
        Index index = indexService.selectByIndexSystemId(indexSystemId);
        //顶级节点的名称
        List<Index> indexList = Lists.newArrayList();
        List<Index> indexList11 = Lists.newArrayList();
        //这是获取原index的id的index集合
        Index index11 = indexService.selectByIndexSystemId(indexSystemId);
        Integer id11 = index11.getId();
        //获取子节点
        List<Index> indexList111 = indexService.selectSunIndexById(id11);
        getIndexChildren1(indexList111, indexList11);
        indexList11.add(index11);

        int a = 0;
        //将顶级节点加入集合

        //获取指标的id
        Integer id2 = index.getId();
        //获取子节点
        List<Index> indexList1 = indexService.selectSunIndexById(id2);
        //递归方法将子节点加入集合
        getIndexChildren(indexList1, indexList, a);
        index.setId(0);
        indexList.add(index);

        //创建统计结果表格
        XWPFTable tableStatisticsResult = document.createTable();
        //设置表级别单元格边距
        tableStatisticsResult.setCellMargins(3, 5, 253, 5);
        //列宽自动分割
        CTTblWidth tableStatisticsResultWidth = tableStatisticsResult.getCTTbl().addNewTblPr().addNewTblW();
        tableStatisticsResultWidth.setType(STTblWidth.DXA);
        tableStatisticsResultWidth.setW(BigInteger.valueOf(9932));


        //创建统计结果标题数组
        String[] indexResult = new String[]{"指标名称", "层级深度", "上下限", "权重"};

        //表格第一行
        for (int i = 0; i < indexList.size() + 1; i++) {
            if (i == 0) {
                XWPFTableRow tableIndexRowOne0 = tableStatisticsResult.getRow(0);
                XWPFTableCell xwpfTableCell10 = tableIndexRowOne0.getCell(0);
                XWPFParagraph xwpfParagraph10 = xwpfTableCell10.addParagraph();
                //垂直居中
                xwpfParagraph10.setAlignment(ParagraphAlignment.CENTER);
                //水平居中
                xwpfParagraph10.setVerticalAlignment(TextAlignment.CENTER);
                XWPFRun run1 = xwpfParagraph10.createRun();
                run1.setText(indexResult[0]);
                run1.setFontSize(12);
                run1.setBold(true);
                run1.setFontFamily("宋体");
                for (int j = 1; j < indexResult.length; j++) {
                    XWPFTableCell xwpfTableCell11 = tableIndexRowOne0.addNewTableCell();

                    //水平居中
                    XWPFParagraph xwpfParagraph1 = xwpfTableCell11.addParagraph();
                    //垂直居中
                    xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                    //水平居中
                    xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                    XWPFRun run11 = xwpfParagraph1.createRun();
                    run11.setText(indexResult[j]);
                    run11.setFontSize(12);
                    run11.setBold(true);
                    run11.setFontFamily("宋体");
                }
            } else {
                String[] titleIndexInfo = new String[]{
                        indexList.get(indexList.size() - i).getName() + "指标体系",
                        indexList.get(indexList.size() - i).getId().toString(),
                        indexList.get(indexList.size() - i).getUpperBound() + "-" + indexList.get(indexList.size() - i).getLowerBound(),
                        indexList.get(indexList.size() - i).getWeight()
                };
                XWPFTableRow tableIndexRowOne = tableStatisticsResult.createRow();
                for (int j = 0; j < indexResult.length; j++) {
                    XWPFTableCell xwpfTableCell1 = tableIndexRowOne.getCell(j);
                    //水平居中
                    XWPFParagraph xwpfParagraph1 = xwpfTableCell1.addParagraph();
                    //垂直居中
                    xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                    //水平居中
                    xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                    XWPFRun run1 = xwpfParagraph1.createRun();
                    run1.setText(titleIndexInfo[j]);
                    run1.setFontSize(12);
                    run1.setBold(false);
                    run1.setFontFamily("宋体");
                }

            }

        }


        //创建小标题6
        XWPFParagraph sixthTitleParagraph = document.createParagraph();
        sixthTitleParagraph.setStyle("标题 1");
        //创建小标题6的段落文本对象的文本
        XWPFRun sixthTitleParagraphRun = sixthTitleParagraph.createRun();
        //设置小标题6下的段落文本的文本
        sixthTitleParagraphRun.setText("7 任务列表");
        //设置小标题6字体颜色
        sixthTitleParagraphRun.setColor("000000");
        //设置大标题字体大小
        sixthTitleParagraphRun.setFontSize(18);
        //设置字体格式
        sixthTitleParagraphRun.setFontFamily("黑体");
        //设置加粗
        sixthTitleParagraphRun.setBold(false);
        //将体系下的末级指标筛查出来
        List<Index> indexList12 = Lists.newArrayList();
        for (Index index1 : indexList11) {
            Integer id1 = index1.getId();
            List<Index> indexList2 = indexService.selectSunIndexById(id1);
            if (indexList2.size() == 0) {
                indexList12.add(index1);
            }
        }
        int biaoTI2 = 1;
        for (Index index111 : indexList12) {
            String name1 = index111.getName();
            //创建小标题5下的文本
            XWPFParagraph sixthTitleContentParagraph = document.createParagraph();
            sixthTitleContentParagraph.setStyle("标题 2");
            //设置首行缩进
            sixthTitleContentParagraph.setIndentationFirstLine(4);
            //创建小标题5下的文本的段落文本对象的文本
            XWPFRun sixthTitleContentParagraphRun = sixthTitleContentParagraph.createRun();
            //创建小标题5下的文本
            sixthTitleContentParagraphRun.setText("7." + biaoTI2 + " 系统设计" + name1 + "指标");
            //设置小标题5下的文本字体颜色
            sixthTitleContentParagraphRun.setColor("000000");
            //设置小标题5下的文本字体大小
            sixthTitleContentParagraphRun.setFontSize(16);
            //设置字体格式
            sixthTitleContentParagraphRun.setFontFamily("黑体");


            //查找工程对应的指标体系,再去找指标体系下所有的指标,再遍历评估任务,找出所有指标对应的评估任务,评估任务mission对应的试验设计
            //保存一个工程下的所有过的试验设计结果集合
            List<ExperimentDesign> experimentDesignList = Lists.newArrayList();
            Integer id1 = index111.getId();
            IndexEvaluationMission indexEvaluationMission = indexEvaluationMissionMapper.selectByIndexId(id1);
            if (indexEvaluationMission != null) {
                Integer id3 = indexEvaluationMission.getId();
                List<ExperimentDesign> experimentDesigns = experimentDesignMapper.selectExperimentDesignByMissionId(id3);
                experimentDesignList.addAll(experimentDesigns);
            }

            if (experimentDesignList.size() > 0) {
                for (ExperimentDesign experimentDesign : experimentDesignList) {
                    //创建统计结果表格
                    XWPFTable experimentDesignResult = document.createTable();
                    //设置表级别单元格边距
                    experimentDesignResult.setCellMargins(3, 5, 153, 5);
                    //列宽自动分割
                    CTTblWidth experimentDesignResultWidth = experimentDesignResult.getCTTbl().addNewTblPr().addNewTblW();
                    experimentDesignResultWidth.setType(STTblWidth.DXA);
                    experimentDesignResultWidth.setW(BigInteger.valueOf(9932));

                    //开始读取试验设计结果的内容
                    String samplespacePath = experimentDesign.getSamplespacePath();

                    DesignSchemeSpaceProcesser designSchemeSpaceProcesser = new DesignSchemeSpaceProcesser();
                    designSchemeSpaceProcesser.loadDesignSchemeSpaceFile(samplespacePath);
                    String designSchemeSpaceJson = designSchemeSpaceProcesser.getDesignSchemeSpaceJson();
                    JSONObject jsonObject = JSON.parseObject(designSchemeSpaceJson);
                    String sampleSpaceItems1 = jsonObject.getString("SampleSpaceItems");
                    JSONObject jsonObject1 = JSON.parseObject(sampleSpaceItems1);
                    JSONArray sampleSpaceItem = jsonObject1.getJSONArray("SampleSpaceItem");
                    //要取到表格的标题头
                    String s = sampleSpaceItem.get(0).toString();
                    JSONObject jsonObject2 = JSON.parseObject(s);
                    String entitiesSampleSpace = jsonObject2.getString("EntitiesSampleSpace");
                    JSONObject jsonObject3 = JSON.parseObject(entitiesSampleSpace.toString());
                    JSONArray jsonObject31 = jsonObject3.getJSONArray("EntityFactor");
                    List<String> nameList = Lists.newArrayList();
                    nameList.add("序号");
                    for (Object o : jsonObject31) {
                        JSONObject jsonObject21 = JSON.parseObject(o.toString());

                        String name = jsonObject21.getString("name");
                        nameList.add(name);
                    }

                    //现在是有多少个试验结果因子的
                    for (int i = 0; i < sampleSpaceItem.size() + 1; i++) {
                        if (i == 0) {
                            XWPFTableRow tableExperimentDesignRowOne0 = experimentDesignResult.getRow(0);
                            tableExperimentDesignRowOne0.setHeight(150);
                            XWPFTableCell xwpfTableCell10 = tableExperimentDesignRowOne0.getCell(0);
                            XWPFParagraph xwpfParagraph10 = xwpfTableCell10.addParagraph();
                            //垂直居中
                            xwpfParagraph10.setAlignment(ParagraphAlignment.CENTER);
                            //水平居中
//                    xwpfParagraph10.setVerticalAlignment(TextAlignment.CENTER);
                            XWPFRun run1 = xwpfParagraph10.createRun();
                            run1.setText(nameList.get(0));
                            run1.setFontSize(12);
                            run1.setBold(true);
                            run1.setFontFamily("宋体");
                            for (int j = 1; j < nameList.size(); j++) {
                                XWPFTableCell xwpfTableCell11 = tableExperimentDesignRowOne0.addNewTableCell();
                                XWPFParagraph xwpfParagraph1 = xwpfTableCell11.addParagraph();
                                //垂直居中
                                xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                                //水平居中
//                        xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                                XWPFRun run11 = xwpfParagraph1.createRun();
                                run11.setText(nameList.get(j));
                                run11.setFontSize(12);
                                run11.setBold(true);
                                run11.setFontFamily("宋体");
                            }
                        } else {
                            List<String> valueList = Lists.newArrayList();
                            //要取到表格的标题头
                            JSONObject jsonObjectT = JSON.parseObject(sampleSpaceItem.get(i - 1).toString());
                            String id111 = jsonObjectT.getString("ID");
                            valueList.add(id111);

                            JSONObject entitiesSampleSpace1 = jsonObjectT.getJSONObject("EntitiesSampleSpace");
                            JSONArray jsonObjectEntityFactor31 = entitiesSampleSpace1.getJSONArray("EntityFactor");
                            for (Object o : jsonObjectEntityFactor31) {

                                JSONObject jsonObject21 = JSON.parseObject(o.toString());

                                String value = jsonObject21.getString("value");
                                valueList.add(value);
                            }


                            XWPFTableRow tableExperimentDesignRowOne = experimentDesignResult.createRow();
                            tableExperimentDesignRowOne.setHeight(150);
                            for (int j = 0; j < nameList.size(); j++) {
                                XWPFTableCell xwpfTableCell1 = tableExperimentDesignRowOne.getCell(j);
                                XWPFParagraph xwpfParagraph1 = xwpfTableCell1.addParagraph();
                                //垂直居中
                                xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                                //水平居中
//                        xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                                XWPFRun run1 = xwpfParagraph1.createRun();
                                run1.setText(valueList.get(j));
                                run1.setFontSize(12);
                                run1.setBold(false);
                                run1.setFontFamily("宋体");
                            }
                        }
                    }
                }
            } else {
                //第二行文本
                XWPFParagraph sixthTitleContentParagraphOne2 = document.createParagraph();
                XWPFRun sixthTitleContentParagraphRunOne2 = sixthTitleContentParagraphOne2.createRun();
                sixthTitleContentParagraphRunOne2.setText("无");
                sixthTitleContentParagraphRunOne2.setColor("000000");
                sixthTitleContentParagraphRunOne2.setFontSize(12);
                sixthTitleContentParagraphRunOne2.setFontFamily("宋体");
            }

            biaoTI2++;
        }


        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph2 = document.createParagraph();
        sixthTitleContentParagraph2.setStyle("标题 1");
        //设置首行缩进
        sixthTitleContentParagraph2.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun2 = sixthTitleContentParagraph2.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun2.setText("8 结果");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun2.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun2.setFontSize(18);
        //设置字体格式
        sixthTitleContentParagraphRun2.setFontFamily("黑体");

        String[] titleSimulation = new String[]{"指标名称", "处理分析方法", "结果"};

        //创建统计结果表格
        XWPFTable tableStatisticsResult1 = document.createTable();
        //设置表级别单元格边距
        tableStatisticsResult1.setCellMargins(3, 5, 153, 5);
        //列宽自动分割
        CTTblWidth tableStatisticsResultWidth1 = tableStatisticsResult1.getCTTbl().addNewTblPr().addNewTblW();
        tableStatisticsResultWidth1.setType(STTblWidth.DXA);
        tableStatisticsResultWidth1.setW(BigInteger.valueOf(9032));

        int heBing = 1;
        for (int i = 0; i < indexList12.size() + 1; i++) {
            if (i == 0) {
                XWPFTableRow tableExperimentDesignRowOne0 = tableStatisticsResult1.getRow(0);
                tableExperimentDesignRowOne0.setHeight(150);
                XWPFTableCell xwpfTableCell10 = tableExperimentDesignRowOne0.getCell(0);
                XWPFParagraph xwpfParagraph10 = xwpfTableCell10.addParagraph();
                //垂直居中
                xwpfParagraph10.setAlignment(ParagraphAlignment.CENTER);
                //水平居中
//                    xwpfParagraph10.setVerticalAlignment(TextAlignment.CENTER);
                XWPFRun run1 = xwpfParagraph10.createRun();
                run1.setText(titleSimulation[0]);
                run1.setFontSize(12);
                run1.setBold(true);
                run1.setFontFamily("宋体");
                for (int j = 1; j < titleSimulation.length; j++) {
                    XWPFTableCell xwpfTableCell11 = tableExperimentDesignRowOne0.addNewTableCell();
                    XWPFParagraph xwpfParagraph1 = xwpfTableCell11.addParagraph();
                    //垂直居中
                    xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                    //水平居中
//                        xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                    XWPFRun run11 = xwpfParagraph1.createRun();
                    run11.setText(titleSimulation[j]);
                    run11.setFontSize(12);
                    run11.setBold(true);
                    run11.setFontFamily("宋体");
                }
            } else {

                Index index1 = indexList12.get(i - 1);
                Integer id1 = index1.getId();
                List<LogEvaluation> logEvaluationList = logEvaluationService.selectByIndexIdAndMethodId(id1);
                int size = logEvaluationList.size();

                for (int j = 0; j < size; j++) {
                    LogEvaluation logEvaluation = logEvaluationList.get(j);
                    Integer methodId = logEvaluation.getMethodId();
                    Method method = methodService.selectByPrimaryKey(methodId);
                    String[] logEvaluationListInfo = new String[]{
                            index1.getName() + "指标",
                            method.getName(),
                            logEvaluation.getContent()
                    };

                    XWPFTableRow tableExperimentDesignRowOne = tableStatisticsResult1.createRow();
                    tableExperimentDesignRowOne.setHeight(150);
                    for (int k = 0; k < logEvaluationListInfo.length; k++) {
                        XWPFTableCell xwpfTableCell1 = tableExperimentDesignRowOne.getCell(k);
                        XWPFParagraph xwpfParagraph1 = xwpfTableCell1.addParagraph();
                        //垂直居中
                        xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                        //水平居中
//                        xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                        XWPFRun run1 = xwpfParagraph1.createRun();
                        run1.setText(logEvaluationListInfo[k]);
                        run1.setFontSize(12);
                        run1.setBold(false);
                        run1.setFontFamily("宋体");
                    }
                }
                int q = heBing;
                heBing = heBing + size - 1;
                mergeCellsVertically(tableStatisticsResult1, 0, q, heBing);
                heBing++;

            }
        }


        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph3 = document.createParagraph();
        sixthTitleContentParagraph3.setStyle("标题 1");
        //设置首行缩进
        sixthTitleContentParagraph3.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun3 = sixthTitleContentParagraph3.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun3.setText("9 建议");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun3.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun3.setFontSize(18);
        //设置字体格式
        sixthTitleContentParagraphRun3.setFontFamily("黑体");


        //第二行文本
        XWPFParagraph sixthTitleContentParagraphOne3 = document.createParagraph();
        XWPFRun sixthTitleContentParagraphRunOne3 = sixthTitleContentParagraphOne3.createRun();
        sixthTitleContentParagraphRunOne3.setText("土豆泥辅导书");
        sixthTitleContentParagraphRunOne3.setColor("000000");
        sixthTitleContentParagraphRunOne3.setFontSize(12);
        sixthTitleContentParagraphRunOne3.setFontFamily("宋体");


        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph4 = document.createParagraph();
        sixthTitleContentParagraph4.setStyle("标题 1");
        //设置首行缩进
        sixthTitleContentParagraph4.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun4 = sixthTitleContentParagraph4.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun4.setText("10 任务详情");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun4.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun4.setFontSize(18);
        //设置字体格式
        sixthTitleContentParagraphRun4.setFontFamily("黑体");
        int biaoTi3 = 1;
        for (Index index111 : indexList12) {
            String name = index111.getName();
            //创建小标题5下的文本
            XWPFParagraph sixthTitleContentParagraph5 = document.createParagraph();
            sixthTitleContentParagraph5.setStyle("标题 2");
            //设置首行缩进
            sixthTitleContentParagraph5.setIndentationFirstLine(4);
            //创建小标题5下的文本的段落文本对象的文本
            XWPFRun sixthTitleContentParagraphRun5 = sixthTitleContentParagraph5.createRun();
            //创建小标题5下的文本
            sixthTitleContentParagraphRun5.setText("11." + biaoTi3 + " 系统设计" + name + "指标");
            //设置小标题5下的文本字体颜色
            sixthTitleContentParagraphRun5.setColor("000000");
            //设置小标题5下的文本字体大小
            sixthTitleContentParagraphRun5.setFontSize(16);
            //设置字体格式
            sixthTitleContentParagraphRun5.setFontFamily("黑体");


            //创建小标题5下的文本
            XWPFParagraph sixthTitleContentParagraph51 = document.createParagraph();
            sixthTitleContentParagraph51.setStyle("标题 3");
            //设置首行缩进
            sixthTitleContentParagraph51.setIndentationFirstLine(4);
            //创建小标题5下的文本的段落文本对象的文本
            XWPFRun sixthTitleContentParagraphRun51 = sixthTitleContentParagraph51.createRun();
            //创建小标题5下的文本
            sixthTitleContentParagraphRun51.setText("11." + biaoTi3 + ".1 方法");
            //设置小标题5下的文本字体颜色
            sixthTitleContentParagraphRun51.setColor("000000");
            //设置小标题5下的文本字体大小
            sixthTitleContentParagraphRun51.setFontSize(14);
            //设置字体格式
            sixthTitleContentParagraphRun51.setFontFamily("黑体");

            Integer id1 = index111.getId();
            List<LogEvaluation> logEvaluationList = logEvaluationService.selectByIndexIdAndMethodId(id1);
            Set<Integer> methodIdList = Sets.newHashSet();
            Set<Integer> dataListSet = Sets.newHashSet();
            if (logEvaluationList.size() > 0) {
                for (LogEvaluation logEvaluation : logEvaluationList) {
                    Integer methodId = logEvaluation.getMethodId();
                    Integer dataId = logEvaluation.getDataId();
                    dataListSet.add(dataId);
                    methodIdList.add(methodId);
                }

                List<Integer> dataList = Lists.newArrayList();
                for (Integer integer : dataListSet) {
                    dataList.add(integer);
                }

                String methodNameList = "";
                for (Integer integer : methodIdList) {
                    Method method = methodService.selectByPrimaryKey(integer);
                    String name1 = method.getName();
                    methodNameList = methodNameList + name1 + "、";
                }
                methodNameList = methodNameList.substring(0, methodNameList.length() - 1);


                //创建小标题5下的文本
                XWPFParagraph sixthTitleContentParagraph511 = document.createParagraph();
                //设置首行缩进
                sixthTitleContentParagraph511.setIndentationFirstLine(4);
                //创建小标题5下的文本的段落文本对象的文本
                XWPFRun sixthTitleContentParagraphRun511 = sixthTitleContentParagraph511.createRun();
                //创建小标题5下的文本
                sixthTitleContentParagraphRun511.setText(methodNameList);
                //设置小标题5下的文本字体颜色
                sixthTitleContentParagraphRun511.setColor("000000");
                //设置小标题5下的文本字体大小
                sixthTitleContentParagraphRun511.setFontSize(12);
                //设置字体格式
                sixthTitleContentParagraphRun511.setFontFamily("宋体");


                //创建小标题5下的文本
                XWPFParagraph sixthTitleContentParagraph52 = document.createParagraph();
                sixthTitleContentParagraph52.setStyle("标题 3");
                //设置首行缩进
                sixthTitleContentParagraph52.setIndentationFirstLine(4);
                //创建小标题5下的文本的段落文本对象的文本
                XWPFRun sixthTitleContentParagraphRun52 = sixthTitleContentParagraph52.createRun();
                //创建小标题5下的文本
                sixthTitleContentParagraphRun52.setText("11." + biaoTi3 + ".2 使用的验证数据");
                //设置小标题5下的文本字体颜色
                sixthTitleContentParagraphRun52.setColor("000000");
                //设置小标题5下的文本字体大小
                sixthTitleContentParagraphRun52.setFontSize(14);
                //设置字体格式
                sixthTitleContentParagraphRun52.setFontFamily("黑体");

                //创建统计结果表格
                XWPFTable tableStatisticsResult52 = document.createTable();
                //设置表级别单元格边距
                tableStatisticsResult52.setCellMargins(3, 5, 253, 5);
                //列宽自动分割
                CTTblWidth tableStatisticsResultWidth52 = tableStatisticsResult52.getCTTbl().addNewTblPr().addNewTblW();
                tableStatisticsResultWidth52.setType(STTblWidth.DXA);
                tableStatisticsResultWidth52.setW(BigInteger.valueOf(9032));

                //创建统计结果标题数组
                String[] dataResult = new String[]{"序号", "数据文件名", "来源"};

                //表格第一行
                for (int i = 0; i < dataList.size() + 1; i++) {
                    if (i == 0) {
                        XWPFTableRow tableIndexRowOne0 = tableStatisticsResult52.getRow(0);
                        XWPFTableCell xwpfTableCell10 = tableIndexRowOne0.getCell(0);
                        XWPFParagraph xwpfParagraph10 = xwpfTableCell10.addParagraph();
                        //垂直居中
                        xwpfParagraph10.setAlignment(ParagraphAlignment.CENTER);
                        //水平居中
                        xwpfParagraph10.setVerticalAlignment(TextAlignment.CENTER);
                        XWPFRun run1 = xwpfParagraph10.createRun();
                        run1.setText(dataResult[0]);
                        run1.setFontSize(12);
                        run1.setBold(true);
                        run1.setFontFamily("宋体");
                        for (int j = 1; j < dataResult.length; j++) {
                            XWPFTableCell xwpfTableCell11 = tableIndexRowOne0.addNewTableCell();

                            //水平居中
                            XWPFParagraph xwpfParagraph1 = xwpfTableCell11.addParagraph();
                            //垂直居中
                            xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                            //水平居中
                            xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                            XWPFRun run11 = xwpfParagraph1.createRun();
                            run11.setText(dataResult[j]);
                            run11.setFontSize(12);
                            run11.setBold(true);
                            run11.setFontFamily("宋体");
                        }
                    } else {
                        Integer integer = dataList.get(i - 1);
                        Data data = dataService.selectByPrimaryKey(integer);
                        String[] titleDataInfo = new String[]{
                                i + "",
                                data.getFileName(),
                                data.getSource()
                        };
                        XWPFTableRow tableIndexRowOne = tableStatisticsResult52.createRow();
                        for (int j = 0; j < titleDataInfo.length; j++) {
                            XWPFTableCell xwpfTableCell1 = tableIndexRowOne.getCell(j);
                            //水平居中
                            XWPFParagraph xwpfParagraph1 = xwpfTableCell1.addParagraph();
                            //垂直居中
                            xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                            //水平居中
                            xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                            XWPFRun run1 = xwpfParagraph1.createRun();
                            run1.setText(titleDataInfo[j]);
                            run1.setFontSize(12);
                            run1.setBold(false);
                            run1.setFontFamily("宋体");

                        }

                    }

                }

            } else {
                //创建小标题5下的文本
                XWPFParagraph sixthTitleContentParagraph511 = document.createParagraph();
                //设置首行缩进
                sixthTitleContentParagraph511.setIndentationFirstLine(4);
                //创建小标题5下的文本的段落文本对象的文本
                XWPFRun sixthTitleContentParagraphRun511 = sixthTitleContentParagraph511.createRun();
                //创建小标题5下的文本
                sixthTitleContentParagraphRun511.setText("无");
                //设置小标题5下的文本字体颜色
                sixthTitleContentParagraphRun511.setColor("000000");
                //设置小标题5下的文本字体大小
                sixthTitleContentParagraphRun511.setFontSize(12);
                //设置字体格式
                sixthTitleContentParagraphRun511.setFontFamily("宋体");
            }


        }


        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph6 = document.createParagraph();
        sixthTitleContentParagraph6.setStyle("标题 1");
        //设置首行缩进
        sixthTitleContentParagraph6.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun6 = sixthTitleContentParagraph6.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun6.setText("12 结论和建议");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun6.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun6.setFontSize(18);
        //设置字体格式
        sixthTitleContentParagraphRun6.setFontFamily("黑体");


        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph61 = document.createParagraph();
        sixthTitleContentParagraph61.setStyle("标题 2");
        //设置首行缩进
        sixthTitleContentParagraph61.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun61 = sixthTitleContentParagraph61.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun61.setText("12.1 结论");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun61.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun61.setFontSize(16);
        //设置字体格式
        sixthTitleContentParagraphRun61.setFontFamily("黑体");


        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph62 = document.createParagraph();
        //设置首行缩进
        sixthTitleContentParagraph62.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun62 = sixthTitleContentParagraph62.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun62.setText("等级:" + "XXX");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun62.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun62.setFontSize(12);
        //设置字体格式
        sixthTitleContentParagraphRun62.setFontFamily("宋体");


        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph63 = document.createParagraph();
        sixthTitleContentParagraph63.setStyle("标题 2");
        //设置首行缩进
        sixthTitleContentParagraph63.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun63 = sixthTitleContentParagraph63.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun63.setText("12.2 层次分析法");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun63.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun63.setFontSize(16);
        //设置字体格式
        sixthTitleContentParagraphRun63.setFontFamily("黑体");

        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph64 = document.createParagraph();
        //设置首行缩进
        sixthTitleContentParagraph64.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun64 = sixthTitleContentParagraph64.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun64.setText("层次分析法结果具体如下:");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun64.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun64.setFontSize(12);
        //设置字体格式
        sixthTitleContentParagraphRun64.setFontFamily("宋体");


        //创建统计结果表格
        XWPFTable tableStatisticsResult62 = document.createTable();
        //设置表级别单元格边距
        tableStatisticsResult62.setCellMargins(3, 5, 3, 5);
        //列宽自动分割
        CTTblWidth tableStatisticsResultWidth62 = tableStatisticsResult62.getCTTbl().addNewTblPr().addNewTblW();
        tableStatisticsResultWidth62.setType(STTblWidth.DXA);
        tableStatisticsResultWidth62.setW(BigInteger.valueOf(9032));


        //创建统计结果标题数组
        String[] indexResult62 = new String[]{"指标名称", "层级深度", "权重", "评估结果"};


        //表格第一行
        for (int i = 0; i < indexList.size() + 1; i++) {
            if (i == 0) {
                XWPFTableRow tableIndexRowOne0 = tableStatisticsResult62.getRow(0);
                XWPFTableCell xwpfTableCell10 = tableIndexRowOne0.getCell(0);
                XWPFParagraph xwpfParagraph10 = xwpfTableCell10.addParagraph();
                //垂直居中
                xwpfParagraph10.setAlignment(ParagraphAlignment.CENTER);
                //水平居中
                xwpfParagraph10.setVerticalAlignment(TextAlignment.CENTER);
                XWPFRun run1 = xwpfParagraph10.createRun();
                run1.setText(indexResult62[0]);
                run1.setFontSize(12);
                run1.setBold(true);
                run1.setFontFamily("宋体");
                for (int j = 1; j < indexResult62.length; j++) {
                    XWPFTableCell xwpfTableCell11 = tableIndexRowOne0.addNewTableCell();

                    //水平居中
                    XWPFParagraph xwpfParagraph1 = xwpfTableCell11.addParagraph();
                    //垂直居中
                    xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                    //水平居中
                    xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                    XWPFRun run11 = xwpfParagraph1.createRun();
                    run11.setText(indexResult62[j]);
                    run11.setFontSize(12);
                    run11.setBold(true);
                    run11.setFontFamily("宋体");
                }
            } else {
                Index index1 = indexList.get(indexList.size() - i);
                Index index2 = indexList11.get(indexList.size() - i);
                Integer id3 = index2.getId();
                String result = logEvaluationService.getIndexAssessmentResultId(id3);

                String[] titleIndexInfo = new String[]{
                        index1.getName() + "指标体系",
                        index1.getId().toString(),
                        index1.getWeight(),
                        result
                };
                XWPFTableRow tableIndexRowOne = tableStatisticsResult62.createRow();
                for (int j = 0; j < titleIndexInfo.length; j++) {
                    XWPFTableCell xwpfTableCell1 = tableIndexRowOne.getCell(j);
                    //水平居中
                    XWPFParagraph xwpfParagraph1 = xwpfTableCell1.addParagraph();
                    //垂直居中
                    xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                    //水平居中
                    xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                    XWPFRun run1 = xwpfParagraph1.createRun();
                    run1.setText(titleIndexInfo[j]);
                    run1.setFontSize(12);
                    run1.setBold(false);
                    run1.setFontFamily("宋体");
                }

            }

        }


        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph7 = document.createParagraph();
        sixthTitleContentParagraph7.setStyle("标题 2");
        //设置首行缩进
        sixthTitleContentParagraph7.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun7 = sixthTitleContentParagraph7.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun7.setText("12.3 模糊评判法");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun7.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun7.setFontSize(16);
        //设置字体格式
        sixthTitleContentParagraphRun7.setFontFamily("黑体");

        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph71 = document.createParagraph();
        //设置首行缩进
        sixthTitleContentParagraph71.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun71 = sixthTitleContentParagraph71.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun71.setText("模糊评判法结果具体如下:");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun71.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun71.setFontSize(12);
        //设置字体格式
        sixthTitleContentParagraphRun71.setFontFamily("宋体");

        //创建统计结果表格
        XWPFTable tableStatisticsResult72 = document.createTable();
        //设置表级别单元格边距
        tableStatisticsResult72.setCellMargins(3, 5, 3, 5);
        //列宽自动分割
        CTTblWidth tableStatisticsResultWidth72 = tableStatisticsResult72.getCTTbl().addNewTblPr().addNewTblW();
        tableStatisticsResultWidth72.setType(STTblWidth.DXA);
        tableStatisticsResultWidth72.setW(BigInteger.valueOf(9032));


        //创建统计结果标题数组
        String[] indexResult72 = new String[]{"工程名称", "评估结果"};

        //表格第一行
        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                XWPFTableRow tableIndexRowOne0 = tableStatisticsResult72.getRow(0);
                XWPFTableCell xwpfTableCell10 = tableIndexRowOne0.getCell(0);
                XWPFParagraph xwpfParagraph10 = xwpfTableCell10.addParagraph();
                //垂直居中
                xwpfParagraph10.setAlignment(ParagraphAlignment.CENTER);
                //水平居中
                xwpfParagraph10.setVerticalAlignment(TextAlignment.CENTER);
                XWPFRun run1 = xwpfParagraph10.createRun();
                run1.setText(indexResult72[0]);
                run1.setFontSize(12);
                run1.setBold(true);
                run1.setFontFamily("宋体");
                for (int j = 1; j < indexResult72.length; j++) {
                    XWPFTableCell xwpfTableCell11 = tableIndexRowOne0.addNewTableCell();

                    //水平居中
                    XWPFParagraph xwpfParagraph1 = xwpfTableCell11.addParagraph();
                    //垂直居中
                    xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                    //水平居中
                    xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                    XWPFRun run11 = xwpfParagraph1.createRun();
                    run11.setText(indexResult72[j]);
                    run11.setFontSize(12);
                    run11.setBold(true);
                    run11.setFontFamily("宋体");
                }
            } else {
                String name1 = project.getName();
                String fceResult = project.getFceResult();
                if (fceResult != null && fceResult != "") {

                } else {
                    fceResult = "未进行模糊评判法";
                }
                String[] titleIndexInfo = new String[]{
                        name1,
                        fceResult
                };
                XWPFTableRow tableIndexRowOne = tableStatisticsResult72.createRow();
                for (int j = 0; j < titleIndexInfo.length; j++) {
                    XWPFTableCell xwpfTableCell1 = tableIndexRowOne.getCell(j);
                    //水平居中
                    XWPFParagraph xwpfParagraph1 = xwpfTableCell1.addParagraph();
                    //垂直居中
                    xwpfParagraph1.setAlignment(ParagraphAlignment.CENTER);
                    //水平居中
                    xwpfParagraph1.setVerticalAlignment(TextAlignment.CENTER);
                    XWPFRun run1 = xwpfParagraph1.createRun();
                    run1.setText(titleIndexInfo[j]);
                    run1.setFontSize(12);
                    run1.setBold(false);
                    run1.setFontFamily("宋体");
                }

            }

        }

        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph73 = document.createParagraph();
        sixthTitleContentParagraph73.setStyle("标题 2");
        //设置首行缩进
        sixthTitleContentParagraph73.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun73 = sixthTitleContentParagraph73.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun73.setText("12.4 综合评估建议");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun73.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun73.setFontSize(16);
        //设置字体格式
        sixthTitleContentParagraphRun73.setFontFamily("黑体");


        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph8 = document.createParagraph();
        sixthTitleContentParagraph8.setStyle("标题 1");
        //设置首行缩进
        sixthTitleContentParagraph8.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun8 = sixthTitleContentParagraph8.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun8.setText("13 风险分析及解决措施");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun8.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun8.setFontSize(18);
        //设置字体格式
        sixthTitleContentParagraphRun8.setFontFamily("黑体");


        //创建小标题5下的文本
        XWPFParagraph sixthTitleContentParagraph9 = document.createParagraph();
        sixthTitleContentParagraph9.setStyle("标题 1");
        //设置首行缩进
        sixthTitleContentParagraph9.setIndentationFirstLine(4);
        //创建小标题5下的文本的段落文本对象的文本
        XWPFRun sixthTitleContentParagraphRun9 = sixthTitleContentParagraph9.createRun();
        //创建小标题5下的文本
        sixthTitleContentParagraphRun9.setText("14 后续工作");
        //设置小标题5下的文本字体颜色
        sixthTitleContentParagraphRun9.setColor("000000");
        //设置小标题5下的文本字体大小
        sixthTitleContentParagraphRun9.setFontSize(18);
        //设置字体格式
        sixthTitleContentParagraphRun9.setFontFamily("黑体");


        String fileName = "模板生成.docx";
        String path = "C:\\Resources\\";
        String uuid = UUID.randomUUID().toString().substring(6);
        File folder = new File(path + uuid);
        if (!folder.exists() && !folder.isDirectory()) {
            folder.mkdirs();
        }
        String pathDoc = folder + "\\" + fileName;
        File templateFile = new File(pathDoc);
        FileOutputStream os = new FileOutputStream(templateFile);
        document.write(os);


        //加载已设置大纲级别的测试文档
        Document doc = new Document(pathDoc);

        //在文档最前面插入一个段落,写入文本并格式化
        Paragraph parainserted = new Paragraph(doc);
        TextRange tr = parainserted.appendText("目 录");
        tr.getCharacterFormat().setBold(false);
        tr.getCharacterFormat().setFontSize(14);

        tr.getCharacterFormat().setTextColor(Color.BLACK);
        doc.getSections().get(0).getParagraphs().insert(20, parainserted);
        parainserted.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);

        //通过域代码添加目录表
        TableOfContent toc1 = new TableOfContent(doc, "{\\o \"1-3\" \\h \\z \\u}");

        doc.getSections().get(0).getParagraphs().get(19).appendTOC(1, 3);
        doc.updateTableOfContents();

//        Section sec = doc.getSections().get(0);
//        sec.getParagraphs().get(40).appendBreak(BreakType.Page_Break);

        //保存文档
        doc.saveToFile(pathDoc, FileFormat.Docx_2010);


        //判断是否是ie浏览器
        if (isMSBrowser(request)) {
            fileName = URLEncoder.encode(fileName, "UTF-8");
        }
        DownloadUtils.downLoadFile(response, fileName, templateFile);


    }

    /**
     * 设置页脚的字体样式
     *
     * @param r1 段落元素
     */
    private void setXWPFRunStyle(XWPFRun r1, String font, int fontSize) {
        r1.setFontSize(fontSize);
        CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr();
        CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts();
        fonts.setAscii(font);
        fonts.setEastAsia(font);
        fonts.setHAnsi(font);
    }

    private List<Index> getIndexChildren1(List<Index> indexList, List<Index> list) {

        for (Index index : indexList) {
            Integer id = index.getId();
            List<Index> selectSunIndexById = indexService.selectSunIndexById(id);

            getIndexChildren1(selectSunIndexById, list);

            list.add(index);
        }
        return list;
    }


    private List<Index> getIndexChildren(List<Index> indexList, List<Index> list, int a) {

        a++;
        for (Index index : indexList) {
            Integer id = index.getId();
            List<Index> selectSunIndexById = indexService.selectSunIndexById(id);

            getIndexChildren(selectSunIndexById, list, a);

            index.setId(a);
            list.add(index);
        }
        return list;
    }

    /**
     * 增加自定义标题样式。这里用的是stackoverflow的源码
     *
     * @param docxDocument 目标文档
     * @param strStyleId   样式名称
     * @param headingLevel 样式级别
     */
    private static void addCustomHeadingStyle(XWPFDocument docxDocument, String strStyleId, int headingLevel) {

        CTStyle ctStyle = CTStyle.Factory.newInstance();
        ctStyle.setStyleId(strStyleId);

        CTString styleName = CTString.Factory.newInstance();
        styleName.setVal(strStyleId);
        ctStyle.setName(styleName);

        CTDecimalNumber indentNumber = CTDecimalNumber.Factory.newInstance();
        indentNumber.setVal(BigInteger.valueOf(headingLevel));

        // lower number > style is more prominent in the formats bar
        ctStyle.setUiPriority(indentNumber);

        CTOnOff onoffnull = CTOnOff.Factory.newInstance();
        ctStyle.setUnhideWhenUsed(onoffnull);

        // style shows up in the formats bar
        ctStyle.setQFormat(onoffnull);

        // style defines a heading of the given level
        CTPPr ppr = CTPPr.Factory.newInstance();
        ppr.setOutlineLvl(indentNumber);
        ctStyle.setPPr(ppr);

        XWPFStyle style = new XWPFStyle(ctStyle);

        // is a null op if already defined
        XWPFStyles styles = docxDocument.createStyles();

        style.setType(STStyleType.PARAGRAPH);
        styles.addStyle(style);

    }


    

    //方法功能描述:判断是否是IE浏览器
    public boolean isMSBrowser(HttpServletRequest request) {
        String[] IEBrowserSignals = {"MSIE", "Trident", "Edge"};
        String userAgent = request.getHeader("User-Agent");
        for (String signal : IEBrowserSignals) {
            if (userAgent.contains(signal)) {
                return true;
            }
        }
        return false;
    }

    /**
     * @Description: 跨列合并
     */
    public void mergeCellsHorizontal(XWPFTable table, int row, int fromCell, int toCell) {
        for (int cellIndex = fromCell; cellIndex <= toCell; cellIndex++) {
            XWPFTableCell cell = table.getRow(row).getCell(cellIndex);
            if (cellIndex == fromCell) {
                // The first merged cell is set with RESTART merge value
                cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
            } else {
                // Cells which join (merge) the first one, are set with CONTINUE
                cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
            }
        }
    }

    /**
     * @Description: 跨行合并
     */
    public void mergeCellsVertically(XWPFTable table, int col, int fromRow, int toRow) {
        for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
            XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
            if (rowIndex == fromRow) {
                // The first merged cell is set with RESTART merge value
                cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
            } else {
                // Cells which join (merge) the first one, are set with CONTINUE
                cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
            }
        }
    }


}

你可能感兴趣的:(poi)