0

我正在使用角度应用程序(角度版本 10)创建带有邮件合并输入字段的文档。一旦用户保存了文档,它将与邮件合并字段一起保存(.docx 格式)

在角度应用程序中插入邮件合并字段我使用以下代码段

 insertField(fieldName: any): void {

let fileName: any = fieldName.replace(/\n/g, '').replace(/\r/g, '').replace(/\r\n/g, '');
let fieldCode: any = 'MERGEFIELD  ' + fileName + '  \\* MERGEFORMAT ';
this.container.documentEditor.editor.insertField(fieldCode, '«' + fieldName + '»');
this.container.documentEditor.focusIn();

}

我想像插入字段一样从角度侧删除这个插入的字段。

我已经尝试过以下一段代码,但它对我不起作用

RemoveFieldInstancesFromEditor(fieldText:string){
let textToFind: string = '«' + fieldText + '»';
let textToReplace: string = "";
if (textToFind !== '') {
    // Find all the occurences of given text
    this.container.documentEditor.searchModule.findAll(textToFind);
    if (this.container.documentEditor.searchModule.searchResults.length > 0) {
        // Replace all the occurences of given text
        this.container.documentEditor.searchModule.searchResults.replaceAll(textToReplace);
        //this.container.documentEditor.searchModule.searchResults.clear();
        
    }
}

}

对此的任何想法将不胜感激

4

1 回答 1

-1

我们根据您的要求创建了一个样本。

我们遵循以下步骤:

当您单击删除时,它将搜索并用空字符串替换内容

请从以下链接获取样本

https://stackblitz.com/edit/75e1qg?file=index.ts

在此示例中,将有一个删除按钮。

参考图片

单击删除按钮将删除名为“shipName”的字段

请让我们知道上面提供的详细信息满足您的要求。

问候,

阿吉塔马林·爱德华

于 2022-03-02T14:15:42.840 回答