No results when setting the firstpage header

2019-07-26 22:26发布

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条回答
何必那么认真
2楼-- · 2019-07-26 22:58

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 headerRibbon sample

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!

查看更多
登录 后发表回答