Reputation: 25
When bulk editing images in the header and footer of word documents via word interop it works perfectly well for most documents. If however the header and footer of a document are collapsed, word crashes.
Now to my question: Can you expand the header/footer section automatically via word interop or do you know of another way to work around this problem?
Additional info:
When expanding the header/footer section manually and saving the document it works again, but that's no reasonable option because there are many documents to edit.
Collapsed header (doesn't work):
The code I'm using for editing header images:
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;
//[...]
}
}
}
Upvotes: 1
Views: 199
Reputation: 25693
It is possible to turn the full page display on/off:
Word.View vw = currentDocument.ActiveWindow.View;
if (vw.DisplayPageBoundaries == false)
{
vw.DisplayPageBoundaries = true;
}
Upvotes: 1