【问题标题】:Word Online add-in silently failing to insert ContentControlWord Online 加载项以静默方式无法插入 ContentControl
【发布时间】:2019-03-01 11:04:20
【问题描述】:

我正在使用 office-js 库为 Microsoft Word 开发插件。在 Mac 桌面版 Word (Office 365) 中一切正常。 但是,当我在 Word 的在线版本上使用相同的加载项时,它会失败。

我遇到的特殊问题是插入 ContentControl。在 Word Online 中,没有插入 ContentControl,尝试插入后的所有命令都没有反映在文档中,但没有抛出错误,继续执行,一切正常。

我在这个 github 项目中简单地复制了这个问题 - https://github.com/lightman76/word-addin-online-problem1

该运行过程的所有非样板代码都在 src/index.js 中

我是否以恰好在桌面 Word 中工作的方式滥用 API,还是 Word 的在线版本存在问题?

【问题讨论】:

    标签: office-js


    【解决方案1】:

    我在 Word Online 上尝试了您的代码,发现了两个问题: 1.不能插入内容控件。 2. 无法更改上下文控件的占位符文本。

    对于#1,您可以更新如下代码,使其适用于所有平台。

    ...
    var pageTitleParagraph = endOfBodyRange.insertParagraph('Works Cited', Word.InsertLocation.after);
    pageTitleParagraph.alignment = Word.Alignment.centered;
    
    // ++++++++Insert an empty paragraph at end of the document+++++++++
    endOfBodyRange = doc.body.getRange(Word.RangeLocation.end);
    var emptyParagraph = endOfBodyRange.insertParagraph('', Word.InsertLocation.after);
    
    var bibRange = pageTitleParagraph.getRange(Word.RangeLocation.after);
    var bibContentControl = bibRange.insertContentControl();
    ...
    

    对于#2,我得到了以下错误。这应该是 Word Online 的限制。

    消息:“Word Online 不支持该操作。有关详细信息,请查看 OfficeExtension.Error.debugInfo。”

    【讨论】:

    • 感谢您提供的解决方法!这让我又开始了。第一个问题对我来说是个大问题,我可以不用占位符文本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-12
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    相关资源
    最近更新 更多