Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void button1_Click(object sender, EventArgs e)
- {
- Microsoft.Office.Interop.Word.Application worddoc = new
- Microsoft.Office.Interop.Word.Application();
- worddoc.Visible = false;
- object docpath = "c:\test.docx";
- object objYes = true;
- object objNo = false;
- object defaultValue = System.Reflection.Missing.Value;
- Document myDoc = worddoc.Documents.Open(ref docpath, ref objNo, ref objNo, ref objNo,
- ref defaultValue,
- ref defaultValue, ref defaultValue, ref defaultValue,
- ref defaultValue, ref defaultValue, ref defaultValue,
- ref defaultValue, ref defaultValue, ref defaultValue,
- ref defaultValue, ref defaultValue);
- if (myDoc.Sections.Count > 0)
- {
- myDoc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddPicture("c:\yay.jpg",
- ref defaultValue, ref defaultValue, ref defaultValue, ref defaultValue,
- ref defaultValue, ref defaultValue, ref defaultValue);
- //^this adds an image to the header.
- foreach (Section section in myDoc.Sections)
- {
- Range headerRange= Section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
- headerRange.Fields.Add(headerRange, WdFieldType.wdFieldPage);
- headerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
- //^sets alignment to the right, this works fine.
- }
- myDoc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text="myTex";
- //^this adds my text to the header, but it overwrites the picture, thus deleting it.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement