Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# Word Interop

Status
Not open for further replies.

JasonSummers

Programmer
Sep 11, 2002
26
US
Hello,

I am trying to programatically add an Image to a word document. I have managed to do that with the COde below. However, I need to insert it into a table that is in the document header. I can insert it into a table in the main body, but cant figure out how to set the range to a cell in a table in the header. Any help will be appreciated.

Thank you.


private void button1_Click(object sender, EventArgs e)
{
//OBJECT OF MISSING "NULL VALUE"
Object oMissing = System.Reflection.Missing.Value;

//OBJECTS OF FALSE AND TRUE
Object oTrue = true;
Object oFalse = false;

//CREATING OBJECTS OF WORD AND DOCUMENT
Word.Application oWord = new Word.Application();
Word.Document oWordDoc = new Word.Document();


//MAKING THE APPLICATION VISIBLE
oWord.Visible = true;

object fileName = @"C:\asheets\Form B03.02A2.DOC";

oWordDoc = oWord.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);


//SETTING FOCUES ON THE PAGE HEADER

oWord.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader;


Word.Shape logoCustom = null;



//THE PATH OF THE LOGO FILE TO BE EMBEDDED IN THE HEADER

String logoPath = "C:\\Test.jpg";


logoCustom = oWord.Selection.HeaderFooter.Shapes.AddPicture(logoPath,ref oFalse, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);



logoCustom.Select(ref oMissing);

logoCustom.Name = "CustomLogo";

logoCustom.Left = (float)Word.WdShapePosition.wdShapeLeft;
}
}
}



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top