【问题标题】:Inserting Editable content control in Word online add-in在 Word 在线加载项中插入可编辑内容控件
【发布时间】:2018-04-11 02:13:54
【问题描述】:

在我的 Word 加载项中,我希望我的用户能够插入带有可编辑内容控件的模板。在 Word 客户端中运行良好,但在 Word 在线版中无法正常运行。

您会在下面找到我的代码。我收到一个调试错误,提示 The action isn't supported in Word Online. Error location : ContentControl.placeholderText。 实际上,当我注释掉行设置 placeholderText 时,我没有收到任何错误。但是我的插件只添加了空文本行,这显然不是我的目的。

Word.run(function (context) {
        var thisDocument = context.document,
            range = thisDocument.getSelection();

            case "ProtagonistsIntroduction":
                var paragraph = range.insertParagraph("Customer", Word.InsertLocation.before);
                paragraph.styleBuiltIn = "Heading1";
                setTemplateContentControlProperties(range, "Mr/Ms. and name", true);
                //I insert here many other content controls
                break;
    })
    .catch(function (error) {
        console.log('Error: ' + JSON.stringify(error));
        if (error instanceof OfficeExtension.Error) {
            console.log('Debug info: ' + JSON.stringify(error.debugInfo));
        }
    });
function setTemplateContentControlProperties(container, placeholderText, lineBreakAfter) {
        var contentControl = container.insertContentControl();
        contentControl.appearance = "BoundingBox";
        contentControl.removeWhenEdited = true;
        contentControl.placeholderText = placeholderText;
        if (lineBreakAfter) {
            contentControl.insertBreak("Line", Word.InsertLocation.after);
        }
        return contentControl;
    }

由于此工具旨在为用户提供文档模板,其中包含他应包含的所有信息,因此我需要这些占位符。 有没有办法解决这个问题?

我可以在 Word Online 中添加文本行而不是内容控件;但是当我在兼容的环境(Word 客户端)中时添加内容控件;如果没有比这更好的了。

干杯!

【问题讨论】:

    标签: javascript office-js


    【解决方案1】:

    无法在 Word Online 中设置 placeholderText 是 Word API 的一个已知限制,如以下 GitHub 问题所述:https://github.com/OfficeDev/office-js/issues/53。我建议您订阅该 GitHub 问题的通知,以便收到产品团队的任何更新通知。

    【讨论】:

    • 好的,谢谢。我是否可以检测到我在 Word Online 中,然后使用其他方法继续?
    • 有一些“帮助 API”可以让您检测主机和平台信息——有关该主题的更多信息,请参阅 this SO answer
    • 谢谢,我去看看!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多