I have a file “test.docx” with 3 page sections, and each section is unlinked from the previous page. Now I want to be able to set a different background/watermark for each section. I just don’t know how to select the other 2 sections (or.. not the first one).
I tried it like this:
Application nWord = new Application();
object oMissing = System.Reflection.Missing.Value;
object fileName = @"E:\test.docx";
Document nDoc = nWord.Documents.Open(ref fileName, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
Shape nShape = null;
for (int i = 0; i < nDoc.Sections.Count; i++)
{
nShape =
nDoc.Sections[i].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,
"TEXT" + i.ToString(), "Arial", (float)36, Microsoft.Office.Core.MsoTriState.msoTrue,
Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, ref oMissing);
nShape.Fill.Visible =
Microsoft.Office.Core.MsoTriState.msoTrue;
nShape.Line.Visible =
Microsoft.Office.Core.MsoTriState.msoFalse;
nShape.Fill.Solid();
nShape.Fill.ForeColor.RGB = (Int32)WdColor.wdColorGray20;
nShape.RelativeHorizontalPosition =
WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
nShape.RelativeVerticalPosition =
WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
nShape.Left = (float)WdShapePosition.wdShapeCenter;
nShape.Top = (float)WdShapePosition.wdShapeCenter;
}
nWord.Visible = true;
but it just drops all 3 watermarks on the first section.
Any ideas?
I actually found a work around, after 3 days of searching and discussing. Here’s my solution: