No results when setting the firstpage header

别来无恙 提交于 2019-12-11 06:16:25

问题


When you look at the documentation for office-js api's you have three header locations:

  • primary
  • firstpage
  • even

I would expect that setting a firstpage header would only show on the first page. However I doesn't seem to do anything. Am I missing something? The documentation is not very clear on this. In this sample only the primary is showing up.

private setHeader(): void {
Word.run((context) => {
    let body = context.document.body;
    let sections = context.document.sections;
    context.load(sections, 'body/style');

    return context.sync()
        .then(() => {
            let primary = sections.items[0].getHeader(Word.HeaderFooterType.primary);
            primary.insertText('primary', Word.InsertLocation.replace)
            let firstPage = sections.items[0].getHeader(Word.HeaderFooterType.firstPage);
            firstPage.insertText('first page', Word.InsertLocation.replace);
            context.sync()
                .then(() => { },
                ((result: OfficeErrorMessage) => {
                    this.setErrorState(result);
                })
            );
            ;
        });
});
}

ps. the sample is typescript.


回答1:


very good question. if you set the headers with the API and then select the 'Different First Page' option on the Design ribbon of the header

you will see that effectively the header is there. The bad part is that we are fixing a bug to make sure its shown, basically we will expose those properties in the section object, we are planning to ship those as part of the next deliverable of the Word js API. Now, those options are actually on the file format (the odd and events on the settings package as <w:evenAndOddHeaders/> , and the 'Different first' a <w:titlePg> element is added on the section definition, so maybe inserting an OOXML can be a workaround for now.

Hope this helps!



来源:https://stackoverflow.com/questions/39164991/no-results-when-setting-the-firstpage-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!