Office.js Word API无法读取纯文本类型的内容控件。

huangapple go评论53阅读模式
英文:

Office.js Word API not able to read plain text type content controls

问题

我正在尝试获取文档中的所有内容控件。根据微软Word API文档,只支持RichText和纯文本类型的内容控件。但我无法获取纯文本类型的内容控件。我只能获取富文本内容控件。

const contentControls = doc.contentControls;
contentControls.load('title, tag, type'); 
return context.sync().then(function () {
  // 遍历内容控件
  console.log(contentControls.items.length);
  for (let i = 0; i < contentControls.items.length; i++) {
    const contentControl = contentControls.items[i];
    console.log(`内容控件 #${i + 1}`);
    console.log('标题:', contentControl.title);
    console.log('标签:', contentControl.tag);
    console.log('类型:', contentControl.type);
  }
});

我尝试使用以下Word API引用:
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
或者
https://appsforoffice.microsoft.com/lib/1/hosted/office.js

但使用这两个引用都只返回富文本内容控件。我是否漏掉了什么,还是Word API仍不支持纯文本类型的内容控件?

英文:

I am trying to get all content controls present in the document. As per microsoft Word API docuemntation only RichText and plain Text type content controls are supported. But i am not able to get the plain text type content controls. I get only richtext content controls.

const contentControls = doc.contentControls;
  contentControls.load(&#39;title, tag, type&#39;); 
  return context.sync().then(function () {
    // Loop through the content controls
    console.log(contentControls.items.length);
    for (let i = 0; i &lt; contentControls.items.length; i++) {
      const contentControl = contentControls.items[i];
      console.log(`Content Control #${i + 1}`);
      console.log(&#39;Title: &#39;, contentControl.title);
      console.log(&#39;Tag: &#39;, contentControl.tag);
      console.log(&#39;Type: &#39;, contentControl.type);
    }
  });

I tried using below WordAPI refrence:
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
OR
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
With both refrences the result contains only richtext content controls.

Am i missing something or plain text type content controls are still not supported via word API?

答案1

得分: 3

纯文本内容控件目前在Word JavaScript API需求集1.5中受支持。请使用Document.getContentControls(options) API。将options参数留空将获取文档中的富文本和纯文本内容控件。如果您只想要纯文本,请指定选项"PlainText"。

英文:

Plain text content controls are currently supported in Word JavaScript API requirement set 1.5. Please use Document.getContentControls(options) API. Leaving the options parameter empty will get both rich text and plain text content controls in the document. If you want plain text only, please specify the option "PlainText".

huangapple
  • 本文由 发表于 2023年7月24日 15:20:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76752189.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定