我正在使用角度应用程序(角度版本 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();
}
}
}
对此的任何想法将不胜感激