如何通过 C# word interop 扩展 Word header 和页脚

How to expand Word header and footer via C# word interop

当通过 word interop 在 word 文档的 header 和页脚中批量编辑图像时,它适用于大多数文档。但是,如果折叠文档的 header 和页脚,word 会崩溃。

现在回答我的问题:您能否通过 word interop 自动扩展 header/footer 部分,或者您知道解决此问题的另一种方法吗?

附加信息:

当手动展开 header/footer 部分并保存文档时,它又可以工作了,但这不是一个合理的选择,因为要编辑的文档很多。

已折叠 header(不起作用):

扩展header(有效):

Word错误信息:

我用来编辑 header 图片的代码:

foreach (Section section in currentDocument.Sections)
{
    HeadersFooters headerFooters = section.Headers;
    foreach (HeaderFooter headerFooter in headerFooters)
    {
        InlineShapes inlineShapes = headerFooter.Range.InlineShapes;
        foreach (InlineShape shape in inlineShapes)
        {
            if (shape.Type != WdInlineShapeType.wdInlineShapePicture)
                continue;
            //[...]
        }
    }
}

可以整页显示on/off:

Word.View vw = currentDocument.ActiveWindow.View;
if (vw.DisplayPageBoundaries == false) 
{
   vw.DisplayPageBoundaries = true;
}