المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : C# Word Interop - Insert Image into a specific cell in a table located in the document header



C# Programming
09-20-2009, 02:41 PM
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 specific cell in 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.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office;
using Word = Microsoft.Office.Interop.Word;
using Microsoft.Office.Interop.Word;


namespace InsertImageIntoWord
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
object missing = System.Reflection.Missing.Value;



object fileName = @"C:\Form100.doc";


ApplicationClass WordApp = new ApplicationClass();


Document odoc = WordApp.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing,


ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing);

WordApp.Active********ActivePane.View.SeekView = Word.WdSeekView.wdSeekPrimaryHeader;

Range rng = odoc.Tables[1].Cell(1, 3).Range;

rng.InlineShapes.AddPicture(@"C:\Test.jpg", ref missing, ref missing, ref missing);

WordApp.Visible = true;


}
}
}