【问题标题】:How insert header and footer in officejs from ooxml of full document如何从完整文档的 ooxml 在 officejs 中插入页眉和页脚
【发布时间】:2017-10-01 14:23:19
【问题描述】:

从一个文档文件中,我正在阅读来自https://msdn.microsoft.com/en-us/library/ee413542(v=office.12).aspx 参考的文档标题。我能够获取标题的 OOXML,但我无法使用 Office 365 插件将其插入到我的在线单词中。 请帮我在在线单词中插入完整文档ooxml的标题。

问候, 普拉文

【问题讨论】:

  • 您能否详细说明一下。标题是固定的,还是您想将文本插入到您的加载项打开的任何文档中?您尝试调用哪种方法?

标签: office365 office-js


【解决方案1】:

找到这个在word文档中插入标题的示例

function insertHeader() {
    Word.run(function (context) {
        var myHeader = context.document.sections.getFirst()
            .getHeader("primary").insertText("This is a header", "start");
        return context.sync();
    }).catch(function(error) {
        console.log(error);
    });
}

    function insertFooter() {

    Word.run(function (ctx) {

        // Create a proxy collection for the sections collection.
        var mySections = ctx.document.sections;

        // Queue a command to load style property of the sections.
        ctx.load(mySections, 'body/style');

        // Synchronize the document state by executing the queued commands,
        // and returning a promise to indicate task completion.
        return ctx.sync().then(function () {

            // Get the primary footer of the first section and create
            // a proxy Body object for the footer.
            var myFooter = mySections.items[0].getFooter("primary");

            // Queue a command to insert a paragraph at the end of the footer.
            myFooter.insertParagraph("Confidential", "end");

            // Queue a command to insert a line break at the end of the footer. 
            myFooter.insertBreak("line", "end");
        })
        // Synchronize the document state by executing the queued commands.
        .then(ctx.sync)
        .then(function () {
            handleSuccess();
        })
        .catch(function (error) {
            handleError(error);
        })
    });
}

【讨论】:

    猜你喜欢
    • 2010-09-26
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    • 2023-03-29
    • 2020-05-26
    相关资源
    最近更新 更多