office-js-docs-reference: Accessing firstPage and evenPages headers throw a general exception

Trying to get the firstPage and evenPages header, I get a general exception. Why? How are we supposed to get the data from the various headers and footers when we do not control the structure of the document we are reading? lelsteph

      const ooxml: OfficeExtension.ClientResult<string> = reportDoc.sections.items[sectionIndex].getHeader(Word.HeaderFooterType.evenPages).getRange('Content').getOoxml();
      await context.sync();
{
    "name": "RichApi.Error",
    "code": "GeneralException",
    "traceMessages": [],
    "innerError": null,
    "debugInfo": {
        "code": "GeneralException",
        "message": "GeneralException",
        "errorLocation": "Range.getOoxml",
        "statement": "range.getOoxml();",
        "surroundingStatements": [
            "var v = context.root._getObjectByReferenceId(\"t!00000537\");",
            "var header = v.getHeader(...);",
            "// Instantiate {header}",
            "var range = header.getRange(...);",
            "// Instantiate {range}",
            "// >>>>>",
            "range.getOoxml();",
            "// <<<<<"
        ],
        "fullStatements": [
            "Please enable config.extendedErrorLogging to see full statements."
        ]
    },
    "httpStatusCode": 500
}

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (13 by maintainers)

Most upvoted comments

Thanks for your response and absolutely agree we should all provide the best experience possible to our customers!

Thanks for clarifying. I was thinking that perhaps you wanted to create a section in the document then try to set that section’s header/footer. I’ll dig around a bit more and get back to you.

Also, if any of these features don’t currently exist, you may want to request them on our Ideas site. Or upvote them if they already exist.