I am using Microsoft.Office.Interop.Word package to add a table in Word Document.
I have already created a table OUTERTABLE *(3*3)*.
Now I want to include another table INNERTABLE (2*2) inside this OUTERTABLE at cell(2,2).
Following is the code I have:
public object InvokeMethod(object obj, string memberName, object[] objParam)
{
return InvokeMember(obj, memberName, BindingFlags.InvokeMethod, objParam);
}
public object SetProperty(object obj, string memberName, object[] objParam)
{
return InvokeMember(obj, memberName, BindingFlags.SetProperty, objParam);
}
public object GetProperty(object obj, string memberName, object[] objParam)
{
return InvokeMember(obj, memberName, BindingFlags.GetProperty, objParam);
}
public object InvokeMember(object obj, string memberName, BindingFlags flag, object[] objParam)
{
// mzimmers 2015 06 29: needed this for something I can't now remember.
try
{
return obj.GetType().InvokeMember(memberName, flag, null, obj, objParam);
}
catch(Exception ex)
{
throw ex;
}
}
object oOuterTable = InvokeMethod(oDocTables, "Add", new object[] { wrdRng, 3, 3, oMissing, oMissing });
//Word.Table oTable = oDoc.Tables.Add(wrdRng, ai_row, ai_col, ref oMissing, ref oMissing);
oGalleryOuterTable = oOuterTable;
object objCell = InvokeMethod(oGalleryOuterTable, "Cell", new object[] { 2, 2 });
object objTR = GetProperty(objCell, "Range", null);
SetProperty(objTR, "Start", new object[] { });
object tblRng = InvokeMethod(objCell, "SetRange", new object[] { objTR, objTR });
object oTable = InvokeMethod(oGalleryOuterTable, "Add", new object[] { tblRng, ai_row, ai_col, oMissing, oMissing });
I Googled and found this article:
wrdRng.SetRange(OUTERTABLE.Cell(2, 2).Range.Start, OUTERTABLE.Cell(2, 2).Range.Start);
I want to replicate the above method by using objects and above Get, Set, Invoke Methods. I am stuck at setting "Range.Start" part.
Not sure how to fix this. Can anyone help me on this? I am not sure about the solution given in that link either.
