1

在我的代码中,我试图更改页脚的字体样式。当我运行以下代码时,我的页脚消失了。

function applyFontPreference(optionNo){
    Word.run(function (context) {
        const sections = context.document.sections;
        sections.load('body/font');
        return context.sync().then(function(){
            var footer = sections.items[0].getFooter("Primary")
            footer.font.name = "Arial";
        });
    }).catch(function (error) {
        console.log("Error: " + error);
        if (error instanceof OfficeExtension.Error) {
            console.log("Debug info: " + JSON.stringify(error.debugInfo));
        };
    });
}
4

1 回答 1

2

问题是属性fontname没有被加载。我在 Script Lab(使用 TypeScript)中进行了测试,问题中的代码出现的错误是

PropertyNotLoaded:属性“名称”不可用。在读取属性值之前,调用包含对象的 load 方法,并在关联的请求上下文中调用“context.sync()”。

放入行以加载属性的同步工作:

    footer.load('font/name');
    await context.sync();
于 2018-11-27T16:45:32.857 回答