Blue Eyed Behemoth Blue Eyed Behemoth - 3 months ago 15
C# Question

Adding Complex Header From One Word Doc to Another

I am using the

AddHeaderFromTo
function from https://msdn.microsoft.com/en-us/library/office/cc546917.aspx. The issue is that it's not taking any images or tables that might be found in the header section of the document. Is there a way to get everything from the header into the other document?

Answer

Using OpenXMLPowerTools I was able to use the following code to take the headers from one file and insert them into another:

var to = @"C:\Users\dheale\Desktop\Word Docs\_Blank_Skeleton.DOCX";
var from = @"C:\Users\dheale\Desktop\Word Docs\Letterheads\StandardLetterhead3.DOCX";
var outDoc = @"C:\Users\dheale\Desktop\Word Docs\test.DOCX";

var sources = new List<Source>
{
    new Source(new WmlDocument(to), false),
    new Source(new WmlDocument(from), true)
};

DocumentBuilder.BuildDocument(sources, outDoc);
Comments