Google apps script 在Google脚本(Google文档)中,如何识别段落对象中的某些单词是否为粗体?

Google apps script 在Google脚本(Google文档)中,如何识别段落对象中的某些单词是否为粗体?,google-apps-script,google-docs,Google Apps Script,Google Docs,假设我在谷歌文档中有这个段落对象: 总统:乔·奥巴姆 如何识别段落对象中是否有某些粗体部分?此外,如何提取粗体字?函数myfunction(){ function myfunction() { var doc = DocumentApp.getActiveDocument(); var body = doc.getBody(); // Analyze the first paragraph in document var paragraph = body.getC

假设我在谷歌文档中有这个段落对象:

总统:乔·奥巴姆

如何识别段落对象中是否有某些粗体部分?此外,如何提取粗体字?

函数myfunction(){
function myfunction() {
    var doc = DocumentApp.getActiveDocument();
    var body = doc.getBody();
    // Analyze the first paragraph in document
    var paragraph = body.getChild(0);
    // assumes the paragraph only has text
    var txt = paragraph.asParagraph().getChild(0);
    var len = txt.asText().getText().length;
    for (var i = 0; i < len; i++) {
        var isbold = txt.asText().isBold(i);
        if (isbold) {
            Logger.log("yes");
            }
        else {
            word = "";
        }   
    }
}
var doc=DocumentApp.getActiveDocument(); var body=doc.getBody(); //分析文档中的第一段 var段落=body.getChild(0); //假定该段落只有文本 var txt=段落.asParagraph().getChild(0); var len=txt.asText().getText().length; 对于(变量i=0;i

此代码将逐个字符检查您的文档,如果单个字符为粗体,它将打印“是”。

不知道使用'isBold()'@lukas lustenberger,
isBold()
在整个段落为粗体时是否可能。但是,如果只有某些单词是粗体的,则会显示
null
。请添加您的搜索/研究工作的简要说明。请不要把代码块放在图像中。使用可用的格式,直接在答案中添加代码。