Office-js: [Word] Header content deleted when loaded for documents with multiple sections

Created on 17 Oct 2018  路  4Comments  路  Source: OfficeDev/office-js

In a Word document with more than 1 section that has headers set to "Same as Previous", loading a section's header via a Word.run function causes the header content to be deleted inadvertently.

Expected Behavior

Header content should not be deleted.

Steps to Reproduce, or Live Example

  1. Create a doc and insert a section (page) break.
  2. Add a header with some text and ensure the 2nd page header has "Link to previous" enabled.
  3. Run this code:
Word.run(async context => {
  const sections = context.document.sections.load([
    'items',
    'text',
  ])
  await context.sync()

  for (const section of sections.items) {
    section.getHeader(Word.HeaderFooterType.primary)
  }
  return await context.sync()
})

Context


At Medtronic, our add-in needs to read the text of every header in a document, instead this is causing users to think our add-in is modifying their document. Not good!

Your Environment

  • Platform: PC desktop, Mac
  • Host [Excel, Word, PowerPoint, etc.]: Word
  • Office version number: 16.18
  • Operating System: macOS High Sierra & Windows 10
  • Browser (if using Office Online): ______

Useful logs

Officejs bug repro - deleting section 2 header on load.docx

Word fixed product bug

All 4 comments

Bump...

Hi Matt, sorry for the delay on this and thanks for provided detailed information about the issue. @JuaneloJuanelo can you look into this? It appears to be a bug - reading the headers causes some of them to disappear. It's reproducible by following Matt's steps outlined above.

@mattblackdev thanks for reporting this issue, yes effectively this is a bug and we are working on a fix. there are 2 fixes we are planning to have here:

  1. when traversing the headers of multiple sections we will return the linked content in all sections.
  2. Even more important we will not remove the content of header/footers after traversing them.

tracking with 2688667

This is fixed!

Was this page helpful?
0 / 5 - 0 ratings