[测评系统]--测评系统核心代码库
林致杰
2022-06-26 99f7f9adac08f3a3fa3211f7a6062c26d62fa224
组别报告解析生成
1个文件已添加
7个文件已修改
556 ■■■■■ 已修改文件
src/main/java/com/ots/common/enums/ReportTypeEnum.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ots/common/utils/poi/WordUtil.java 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ots/framework/web/controller/BaseController.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ots/project/exam/domain/TReportTemplate.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ots/project/tool/PdfUtil.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ots/project/tool/report/MAQ/base/RowData.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ots/project/tool/report/MAQ/base/SeriesData.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java 421 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ots/common/enums/ReportTypeEnum.java
@@ -4,7 +4,7 @@
@Getter
public enum ReportTypeEnum {
    Brief("Brief", "简易版"), Complete("Complete", "完整版"), SAQ("SAQ", "SAQ报告"), RuiLin("RuiLin", "睿邻报告"), CAQ("CAQ", "CAQ报告"),
    JAQ("JAQ","JAQ报告"),MAQ("MAQ", "MAQ报告"),MAQV2("MAQV2", "MAQV2报告"),PAQ("PAQ", "PAQ报告"),MAQIAR("MAQIAR", "MAQIAR报告");
    JAQ("JAQ","JAQ报告"),MAQ("MAQ", "MAQ报告"),MAQV2("MAQV2", "MAQV2报告"),PAQ("PAQ", "PAQ报告"),MAQIAR("MAQIAR", "MAQIAR报告"),MAQTR("MAQTR", "MAQTR报告");
    private final String code;
    private final String message;
    ReportTypeEnum(String code, String message) {
src/main/java/com/ots/common/utils/poi/WordUtil.java
@@ -17,6 +17,7 @@
import com.ots.project.tool.exam.ExamUtil;
import com.ots.project.tool.exam.ImageUtil;
import com.ots.project.tool.exam.ZipUtil;
import com.ots.project.tool.report.MAQTR.chart.MAQTRChart;
import com.ots.project.tool.report.PAQ.chart.PAQChart;
import org.apache.commons.collections.map.HashedMap;
import org.apache.poi.ooxml.POIXMLDocument;
@@ -1168,15 +1169,16 @@
            out = getDownLoadFileOutputStream(reportName);
            
            log.info("reportTemplate:" + fileName);
            String templateType = tReportTemplate.getTemplateType();
            setChageWord(fileName, out, textMap, tReportTemplate.getReportType(), templateType, autoTableMap);
            //String templateType = tReportTemplate.getTemplateType();
            setChageWord(fileName, out, textMap, tReportTemplate.getReportType(),tReportTemplate.getDataPath(), autoTableMap);
            out.flush();
            changColorIfJAQ(textMap, out, reportName, tReportTemplate.getReportType());
            //PAQ采用新的doc转pdf
            if(!ReportTypeEnum.PAQ.getCode().equals(reportType)){
                ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/");
            }else{
            //PAQ、MAQTR采用新的doc转pdf
            if(ReportTypeEnum.PAQ.getCode().equals(reportType) || ReportTypeEnum.MAQTR.getCode().equals(reportType)){
                PdfUtil.convertPDF(EssConfig.getProfile() + "/" + reportName);
            }else{
                ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/");
            }
            zipFilePath = getPdfPath(reportName);
            
@@ -1255,8 +1257,20 @@
        }
        return new FileOutputStream(outFile);
    }
    private static void setChageWord(String fileName, OutputStream out, Map<String, Object> textMap, String reportType, String templateType, Map<Integer, Map<Integer, List<String[]>>> autoTableMap) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException, DocumentException {
        String filePath = getTemplateDownLoadPathByUpLoad(fileName);
    /**
     * 内容变更
     * @param fileName
     * @param out
     * @param textMap
     * @param reportType
     * @param autoTableMap
     * @throws IOException
     * @throws InvalidFormatException
     * @throws DocumentException
     */
    private static void setChageWord(String fileName, OutputStream out, Map<String, Object> textMap, String reportType,String dataPath, Map<Integer, Map<Integer, List<String[]>>> autoTableMap) throws IOException, InvalidFormatException, DocumentException {
        //String filePath = getTemplateDownLoadPathByUpLoad(fileName);
        
        XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(getTemplateDownLoadPathByUpLoad(fileName)));
@@ -1266,11 +1280,6 @@
        //设置文本框
        changeTextBox(document, textMap);
        //设置图表
        if (Objects.equals(reportType, ReportTypeEnum.PAQ.getCode())) {
            PAQChart.changeChart(document, textMap);
        }
        //插入表格
        addTableValue(document, autoTableMap);
@@ -1278,7 +1287,7 @@
        changeTable(document, textMap);
        //设置图表控件
        changChar(textMap, document, reportType, templateType);
        changChart(textMap, document, reportType,dataPath);
        document.write(out);
    }
    private static void changeTextBox(XWPFDocument document, Map<String, Object> textMap) throws DocumentException {
@@ -1365,13 +1374,13 @@
    /**
     * 设置图标控件
     * @param textMap
     * @param document
     * @param reportType
     * @param templateType
     * @param textMap 替换text
     * @param document 报告文件
     * @param reportType 报告类型
     * @param dataPath MAQTR数据路径
     */
    private static void changChar(Map<String, Object> textMap, XWPFDocument document, String reportType, String templateType) {
        if (StringUtils.isEmpty(reportType) || StringUtils.isEmpty(templateType)) {
    private static void changChart(Map<String, Object> textMap, XWPFDocument document, String reportType,String dataPath) {
        if (StringUtils.isEmpty(reportType)) {
            return;
        }
        List<XWPFChart> charts = document.getCharts();
@@ -1384,6 +1393,10 @@
            setMAQ_V2CompleteChars(textMap, charts);
        } else if (StringUtils.equals(reportType, ReportTypeEnum.RuiLin.getCode())) {
            setRuiLinChar(textMap, charts);
        } else if (StringUtils.equals(reportType, ReportTypeEnum.PAQ.getCode())) {
            PAQChart.changeChart(document, textMap);
        } else if (StringUtils.equals(reportType, ReportTypeEnum.MAQTR.getCode())) {
            MAQTRChart.changeMAQTRChart(document, dataPath);
        } else {
            return;
        }
@@ -1600,7 +1613,7 @@
        }
    }
    public File getAbsoluteFileZipByName(String filename) {
        String downloadPath = EssConfig.getDownloadPath() + filename;
        String downloadPath = EssConfig.getDownloadPath() + "/" + filename;
        File desc = new File(downloadPath);
        if (!desc.getParentFile().exists()) {
            desc.getParentFile().mkdirs();
src/main/java/com/ots/framework/web/controller/BaseController.java
@@ -1,4 +1,5 @@
package com.ots.framework.web.controller;
import cn.hutool.core.util.URLUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ots.common.utils.DateUtils;
@@ -11,9 +12,19 @@
import com.ots.framework.web.page.TableDataInfo;
import com.ots.framework.web.page.TableSupport;
import com.ots.project.system.user.domain.User;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.beans.PropertyEditorSupport;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
@@ -112,4 +123,39 @@
        }
        return json;
    }
    public void downDeviceManagementTemplate(String fileName, String path , HttpServletRequest req, HttpServletResponse res) throws UnsupportedEncodingException {
        // 读取服务器端模板文件
        // ClassPathResource类的构造方法接收路径名称,自动去classpath路径下找文件
        ClassPathResource classPathResource = new ClassPathResource(path);
        //创建临时文件
        XSSFWorkbook workbook = null;
        try (InputStream inputStream = classPathResource.getInputStream()) {
            // 转为POI的Workbook输出流,这样下载后 打开不报错,直接输出  流 的话,打开excel可能提示错误
            workbook = new XSSFWorkbook(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("模板下载异常");
        }
        String userAgent = req.getHeader("User-Agent");
        // 针对IE或者以IE为内核的浏览器:
        if(userAgent.contains("MSIE")||userAgent.contains("Trident")) {
            fileName = URLUtil.encode(fileName, Charset.forName("UTF-8"));
        } else {
            // 非IE浏览器的处理:
            fileName = new String(fileName.getBytes("UTF-8"),"ISO-8859-1");
        }
        res.setHeader("Content-disposition", "attachment; filename=" + fileName);
        res.setContentType("application/vnd.ms-excel; charset=utf-8");
        res.setCharacterEncoding("UTF-8");
        // 将流中内容写出去
        try (OutputStream outputStream = res.getOutputStream()) {
            workbook.write(outputStream);
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("模板下载异常");
        }
    }
}
src/main/java/com/ots/project/exam/domain/TReportTemplate.java
@@ -23,5 +23,11 @@
    
    @Excel(name = "模板地址")
    private String location;
    private MultipartFile locationFile;
    /**
     * 数据地址
     */
    private String dataPath;
}
src/main/java/com/ots/project/tool/PdfUtil.java
@@ -48,7 +48,7 @@
    public static void main(String[] args) {
        //convertPDF("D:\\测评系统\\home\\林_PAQ_GS_TH.docx");
        convertPDF("D:\\测评系统\\home\\uploadPath\\测试2_PAQ_GS_CN.docx");
        convertPDF("C:\\Users\\大头\\Desktop\\MAQ组别报告\\测试_MAQTR_IA_EN.docx");
    }
}
src/main/java/com/ots/project/tool/report/MAQ/base/RowData.java
@@ -10,8 +10,6 @@
 * @create: 2021-06-07 23:30
 **/
@Data
@NoArgsConstructor                 //无参构造
@AllArgsConstructor                //有参构造
public class RowData {
    public String name;
@@ -20,4 +18,23 @@
     */
    public double value;
    public String valueStr;
    public RowData() {
    }
    public RowData(String name) {
        this.name = name;
    }
    public RowData(String name, double value) {
        this.name = name;
        this.value = value;
    }
    public RowData(String name, double value, String valueStr) {
        this.name = name;
        this.value = value;
        this.valueStr = valueStr;
    }
}
src/main/java/com/ots/project/tool/report/MAQ/base/SeriesData.java
@@ -23,4 +23,7 @@
    public List<RowData> value;
    public SeriesData(String name) {
        this.name = name;
    }
}
src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java
New file
@@ -0,0 +1,421 @@
package com.ots.project.tool.report.MAQTR.chart;
import com.alibaba.fastjson.JSON;
import com.ots.common.utils.StringUtils;
import com.ots.project.tool.report.MAQ.base.RowData;
import com.ots.project.tool.report.MAQ.base.SeriesData;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFChart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.openxmlformats.schemas.drawingml.x2006.chart.*;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * @description: MAQTR图表 带直线和数据标记散点图数据变更
 * @author: zhijie
 * @create: 2022-06-16 22:01
 **/
@Slf4j
public class MAQTRChart {
    public static void main(String[] args) throws IOException {
        try {
            OutputStream os = new FileOutputStream("C:\\Users\\大头\\Desktop\\MAQ组别报告\\林_PAQ_IA_CN1.docx");
            XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage("C:\\Users\\大头\\Desktop\\MAQ组别报告\\终稿【0607中文版】MAQ组别对比报告.docx"));
            String fileName = "C:\\Users\\大头\\Desktop\\MAQ组别报告\\MAQ组别导入数据模板.xlsx";
            //变更图表数据
            changeMAQTRChart(document,fileName);
            document.write(os);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 初始化报告数据
     * @param fileName 数据源文件名
     * @param index 模板sheet索引
     * @return
     */
    public static List<SeriesData> initData(String fileName,Integer index){
        List<SeriesData> seriesDatas = new ArrayList<>();
        try {
            XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(fileName));
            XSSFSheet sheet1 = wb.getSheetAt(index);
            //数据处理  先获取表头长度  遍历表头行数、一一对应放进表头集合里
            Map<Integer,SeriesData> map = new HashMap<>();
            XSSFRow row = sheet1.getRow(0);
            for (int i = 0; i < row.getLastCellNum(); i++) {
                //为空忽略
                /*if(StringUtils.isEmpty(getName(row.getCell(i)))){
                    continue;
                }*/
                SeriesData seriesData = new SeriesData(getName(row.getCell(i)));
                map.put(i,seriesData);
                //读取每一行每一列
                for (int j = 1; j <= sheet1.getLastRowNum(); j++) {
                    //每一行
                    XSSFRow row1 = sheet1.getRow(j);
                    RowData rowData = new RowData();
                    if(seriesData.getValue() == null){
                        List<RowData> rowDatas = new ArrayList<>();
                        //设置表头
                        rowData.setName(getName(row.getCell(i)));
                        //根据类型判断赋值
                        switch (row1.getCell(i).getCellType()) {
                            case STRING:
                                rowData.setValueStr(row1.getCell(i).getStringCellValue());
                                break;
                            case NUMERIC:
                                rowData.setValue(row1.getCell(i).getNumericCellValue());
                                break;
                            default:
                                break;
                        }
                        rowDatas.add(rowData);
                        seriesData.setValue(rowDatas);
                    }else{
                        //设置表头
                        rowData.setName(getName(row.getCell(i)));
                        //根据类型判断赋值
                        switch (row1.getCell(i).getCellType()) {
                            case STRING:
                                rowData.setValueStr(row1.getCell(i).getStringCellValue());
                                break;
                            case NUMERIC:
                                rowData.setValue(row1.getCell(i).getNumericCellValue());
                                break;
                            default:
                                break;
                        }
                        seriesData.getValue().add(rowData);
                    }
                }
                seriesDatas.add(seriesData);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return seriesDatas;
    }
    /**
     * 根据单元格类型取值
     * @return 返回字符值
     */
    private static String getName(XSSFCell cell){
        String name = null;
        switch (cell.getCellType()) {
            case STRING:
                name = cell.getStringCellValue();
                break;
            case NUMERIC:
                name = cell.getNumericCellValue()+"";
                break;
        }
        return name;
    }
    /**
     * 替换MAQTR图表数据
     * @param document 文档对象
     * @param fileName 数据源excel
     */
    public static void changeMAQTRChart(XWPFDocument document,String fileName) {
        if(StringUtils.isEmpty(fileName)){
            return;
        }
        try {
            List<POIXMLDocumentPart> relations = document.getRelations();
            for (POIXMLDocumentPart part : relations) {
                if (part instanceof XWPFChart) {
                    // 图表元素
                    XWPFChart chart = (XWPFChart) part;
                    String partName = chart.getPackagePart().getPartName().getName();
                    Integer index = 0;
                    if(partName.contains("chart1.xml")){
                        index = 0;
                    }else if(partName.contains("chart2.xml")){
                        index = 1;
                    }
                    //获取模板数据
                    List<SeriesData> seriesDatas = initData(fileName,index);
                    //数据长度
                    int size = seriesDatas.size();
                    // 查看里面的图表数据,才能知道是什么图表
                    CTPlotArea plot = chart.getCTChart().getPlotArea();
                    // excel内置表格
                    XSSFWorkbook workbook = chart.getWorkbook();
                    XSSFSheet sheet = workbook.getSheetAt(0);
                    //散点图
                    if (!plot.getScatterChartList().isEmpty()) {
                        CTScatterChart scatterChart = plot.getScatterChartArray(0);
                        //去除多余数据源
                        int remain = 8 - size;
                        if(remain != 0){
                            for (int j = 1; j <= remain; j++) {
                                int removeSize = scatterChart.getSerList().size() - j - 1;
                                scatterChart.getSerList().remove(removeSize);
                                //删除excel多余列
                                //deleteColumn(sheet,8 - remain);
                            }
                        }
                        //刷新内置excel数据
                        refreshExcel(seriesDatas, sheet);
                        workbook.write(chart.getPackagePart().getOutputStream());
                        //散点图数据源 XY坐标
                        for (int i = 0; i < scatterChart.getSerList().size(); i++) {
                            //根据图表数据线获取对应数据源  数值是X轴 辅助Y轴
                            List<SeriesData> scatterDatas = new ArrayList<SeriesData>();
                            //最后一个数据源需拿取最后一列0000 作为x轴
                            if((i+1) == size-2){
                                scatterDatas.add(seriesDatas.get(size-1));
                                scatterDatas.add(seriesDatas.get(size-2));
                            }else{
                                scatterDatas.add(seriesDatas.get(i+1));
                                scatterDatas.add(seriesDatas.get(size-2));
                            }
                            CTScatterSer ser = scatterChart.getSerList().get(i);
                            updateScatterChart(scatterDatas, ser.getXVal(), ser.getYVal());
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("MAQTR替换word图表 散点图图形失败:{}",e);
        }
    }
    /**
     * 删除列
     * @param sheet
     * @param columnToDelete
     */
    public static void deleteColumn(XSSFSheet sheet, int columnToDelete) {
        for (int r = 0; r <= sheet.getLastRowNum(); r++) {
            XSSFRow row = sheet.getRow(r);
            for (int c = columnToDelete; c <= row.getLastCellNum(); c++) {
                XSSFCell cOld = row.getCell(c);
                if (cOld != null) {
                    row.removeCell(cOld);
                }
                XSSFCell cNext = row.getCell(c + 1);
                if (cNext != null) {
                    XSSFCell cNew = row.createCell(c, cNext.getCellType());
                    cloneCell(cNew, cNext);
                    if (r == 0) {
                        sheet.setColumnWidth(c, sheet.getColumnWidth(c + 1));
                    }
                }
            }
        }
    }
    /**
     * 右边列左移,样式值设置
     * @param cNew
     * @param cOld
     */
    private static void cloneCell(XSSFCell cNew, XSSFCell cOld) {
        cNew.setCellComment(cOld.getCellComment());
        cNew.setCellStyle(cOld.getCellStyle());
        if (CellType.BOOLEAN == cNew.getCellType()) {
            cNew.setCellValue(cOld.getBooleanCellValue());
        } else if (CellType.NUMERIC == cNew.getCellType()) {
            cNew.setCellValue(cOld.getNumericCellValue());
        } else if (CellType.STRING == cNew.getCellType()) {
            cNew.setCellValue(cOld.getStringCellValue());
        } else if (CellType.ERROR == cNew.getCellType()) {
            cNew.setCellValue(cOld.getErrorCellValue());
        } else if (CellType.FORMULA == cNew.getCellType()) {
            cNew.setCellValue(cOld.getCellFormula());
        }
    }
    /**
     * 更新图表的关联 excel
     *
     * @param seriesDatas
     * @param sheet
     */
    protected static void refreshExcel(List<SeriesData> seriesDatas, XSSFSheet sheet) {
        XSSFRow title = sheet.getRow(0);
        //遍历数据数组进行excel赋值
        for (int i = 0; i < seriesDatas.size(); i++) {
            SeriesData data = seriesDatas.get(i);
            if (data.name != null && !data.name.isEmpty()) {
                // 第一行标题
                XSSFCell cell = title.getCell(i);
                if (cell == null) {
                    cell = title.createCell(i + 1);
                }
                cell.setCellValue(data.name);
            }
            int size = data.value.size();
            //遍历数据进行赋值
            for (int j = 0; j < size; j++) {
                //从第二行开始赋值
                XSSFRow row = sheet.getRow(j + 1);
                if (row == null) {
                    row = sheet.createRow(j + 1);
                }
                RowData cellValu = data.value.get(j);
                //第一列开始赋值
                XSSFCell cell = row.getCell(i);
                if (cell == null) {
                    cell = row.createCell(i);
                }
                //优先使用字符串值
                if(StringUtils.isNotEmpty(cellValu.valueStr)){
                    cell.setCellValue(cellValu.valueStr);
                }else{
                    cell.setCellValue(cellValu.value);
                }
            }
            //删除多余行数
            int lastRowNum = sheet.getLastRowNum();
            //log.error("lastRowNum:{},size:{}",lastRowNum,size);
            if (lastRowNum > size) {
                for (int idx = lastRowNum; idx > size; idx--) {
                    sheet.removeRow(sheet.getRow(idx));
                }
            }
        }
    }
    /**
     * 更新 散点图 缓存数据
     *
     * @param seriesDatas 数据
     * @param xDataSource X坐标数据缓存
     * @param yDataSource Y坐标数据缓存
     */
    protected static void updateScatterChart(List<SeriesData> seriesDatas, CTAxDataSource xDataSource,
                                             CTNumDataSource yDataSource) {
        //获取xy坐标数据条数
        long xNumCnt = xDataSource.getNumRef().getNumCache().getPtCount().getVal();
        long yNumCnt = yDataSource.getNumRef().getNumCache().getPtCount().getVal();
        //获取XY最新数据
        List<RowData> xRowDatas = seriesDatas.get(0).getValue();
        int xRowDataSize = xRowDatas.size();
        List<RowData> yRowDatas = seriesDatas.get(1).getValue();
        int yRowDataSize = yRowDatas.size();
        //更新X坐标缓存
        for (int i = 0; i < xRowDatas.size(); i++) {
            RowData cellValu = xRowDatas.get(i);
            CTNumVal val = xNumCnt > i ? xDataSource.getNumRef().getNumCache().getPtArray(i)
                    : xDataSource.getNumRef().getNumCache().addNewPt();
            val.setIdx(i);
            val.setV(String.format("%.0f", cellValu.value));
        }
        //更新Y坐标缓存
        for (int i = 0; i < yRowDatas.size(); i++) {
            RowData cellValu = yRowDatas.get(i);
            CTNumVal val = yNumCnt > i ? yDataSource.getNumRef().getNumCache().getPtArray(i)
                    : yDataSource.getNumRef().getNumCache().addNewPt();
            val.setIdx(i);
            val.setV(String.format("%.0f", cellValu.value));
        }
        // 更新对应excel的范围
        xDataSource.getNumRef().setF(
                replaceRowEnd(xDataSource.getNumRef().getF(),
                        xNumCnt,
                        xRowDataSize));
        yDataSource.getNumRef().setF(
                replaceRowEnd(yDataSource.getNumRef().getF(),
                        yNumCnt,
                        yRowDataSize));
        // 删除多的
        if (xNumCnt > xRowDataSize) {
            for (int idx = xRowDataSize; idx < xNumCnt; idx++) {
                xDataSource.getNumRef().getNumCache().removePt(xRowDataSize);
            }
        }
        if (yNumCnt > yRowDataSize) {
            for (int idx = yRowDataSize; idx < yNumCnt; idx++) {
                yDataSource.getNumRef().getNumCache().removePt(yRowDataSize);
            }
        }
        // 更新个数
        xDataSource.getNumRef().getNumCache().getPtCount().setVal(xRowDataSize);
        // 更新个数
        yDataSource.getNumRef().getNumCache().getPtCount().setVal(yRowDataSize);
    }
    /**
     * 替换 形如: Sheet1!$A$2:$A$4 的字符
     *
     * @param range
     * @return
     */
    public static String replaceRowEnd(String range, long oldSize, long newSize) {
        Pattern pattern = Pattern.compile("(:\\$[A-Z]+\\$)(\\d+)");
        Matcher matcher = pattern.matcher(range);
        if (matcher.find()) {
            long old = Long.parseLong(matcher.group(2));
            return range.replaceAll("(:\\$[A-Z]+\\$)(\\d+)", "$1" + Long.toString(old - oldSize + newSize));
        }
        return range;
    }
    /**
     * 获取图表有哪些类型
     * @param part
     */
    public static void getChartType(POIXMLDocumentPart part){
        XWPFChart chart = (XWPFChart) part;
        //根据属性第一列名称切换数据类型
        CTChart ctChart = chart.getCTChart();
        CTPlotArea plotArea = ctChart.getPlotArea();
        if (!plotArea.getBarChartList().isEmpty()) {
            System.out.println("柱状图{"+plotArea.getBarChartList().size()+"}");
        }
        if (!plotArea.getPieChartList().isEmpty()) {
            System.out.println("饼图{"+plotArea.getPieChartList().size()+"}");
        }
        if (!plotArea.getLineChartList().isEmpty()) {
            System.out.println("线形图{"+plotArea.getLineChartList().size()+"}");
        }
        if (!plotArea.getBar3DChartList().isEmpty()) {
            System.out.println("柱状图3D{"+plotArea.getBar3DChartList().size()+"}");
        }
        if (!plotArea.getScatterChartList().isEmpty()) {
            System.out.println("散点图{"+plotArea.getScatterChartList().size()+"}");
        }
    }
}