package com.limap.common.utils.poi;

import com.limap.common.utils.poi.parser.*;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

/**
 * @author Lenovo
 */
public class PoiUtil {

    /**
     * <p>word模板文字、表格、图表内容替换</p>
     *
     * @author Allen Yang
     * @datetime 2021/11/19 11:11
     */
    public static WordContentParser replaceWordContent(WordContentParserVO param) {
        XWPFDocument doc = WordContentParser.loadXWPFDocument(param.getPath());
        //文字替换
            WordParagraphParser paragraphParser = new WordParagraphParser(doc, param.getTextReplaceMap());
            paragraphParser.replace();

        //表格替换
        if(param.getTableReplaces() != null){
            WordTableParser tableParser = new WordTableParser(doc, param.getTableReplaces(), param.getTextReplaceMap());
            tableParser.replace();
        }

        //图表替换
        if(param.getChartReplaces() != null){
            WordChartParser chartParser = new WordChartParser(doc, param.getChartReplaces());
            chartParser.replace();
//            chartParser.generateChart();
        }

        //图片替换
        if(param.getPictureReplaces() != null){
            WordPictureParser pictureParser = new WordPictureParser(doc, param.getPictureReplaces());
            pictureParser.replace();
        }

        return paragraphParser;
    }

}
