如何使用App脚本在现有Google文档中合并RTF字符串?

问题描述 投票:0回答:1

我正在一个项目中,我必须在现有的google文档中合并RTF字符串。

示例:我有一个Google文档,它包含诸如{{Description}}之类的字段合并,Description是RTF文本字段,我想用我的RTF文本字段替换{{Description}}。我怎样才能做到这一点?我尝试使用replaceText函数,但是已将其替换为计划HTML文本,例如<b><i><u>some description text </u></i><b>

我的目标是在将富文本格式替换为现有的google docs字段合并时将其保留。

非常感谢!

google-apps-script rtf richtext
1个回答
0
投票

对我来说这很有效:

[Convert HTML Content into Plain Text from Amit Agarwal。

function htmlToText(){

var html = "<b><i><u>some description text </u></i><b>";
var doc = DocumentApp.openById("XXX");
var body = doc.getBody();
body.appendParagraph(html.replace(/<\/?[^>]+>/ig, " "));

}

//一些描述文字

© www.soinside.com 2019 - 2024. All rights reserved.