在占位符位置生成表格时,结尾多余了占位符内容

//定义默认查找替换选项
FindReplaceOptions options = new FindReplaceOptions();
options.setReplacingCallback(new ReplaceWithCustomTableHandler(tableData));
// 替换表格占位符
document.getRange().replace(placeholderName, "", options);
public class ReplaceWithCustomTableHandler implements IReplacingCallback {
    private final Map<String, Object> tableData;

    // 构造方法接收表格数据
    public ReplaceWithCustomTableHandler(Map<String, Object> tableData) {
        this.tableData = tableData;
    }

    @Override
    public int replacing(ReplacingArgs args) throws Exception {
        // 获取文档对象
        Document doc = (Document) args.getMatchNode().getDocument();
        DocumentBuilder builder = new DocumentBuilder(doc);
        // 定位到占位符
        builder.moveTo(args.getMatchNode());
        // 获取表头和数据
        List<String> headers = (List<String>) tableData.get("header"); // 表头
        List<List<Object>> tableDataList = (List<List<Object>>) tableData.get("tableDataList");// 数据集
        DocumentTableUtil.addTable(builder, doc, headers, tableDataList);
        //删除占位符
        args.getMatchNode().remove();
        return ReplaceAction.SKIP; // 跳过默认替换
    }
}

@JOOL 出现此问题的原因是匹配的文本可以使用多个节点表示。这绝对是常见的情况。您可以使用以下主题中建议的方法来解决问题:
https://forum.aspose.com/t/replacing-text-with-image/268339/2

或者,您可以执行两次替换操作。第一次将占位符表示为单个 RUN,第二次使用 IReplacingCallback 实现替换它:

// Replace placeholder with itself to make it to be represented as single Run.
document.getRange().replace(placeholderName, placeholderName);

FindReplaceOptions options = new FindReplaceOptions();
options.setReplacingCallback(new ReplaceWithCustomTableHandler(tableData));
document.getRange().replace(placeholderName, "", options);