问题
I created a table in word document using c#, I am trying to add row to the end of the table. for now I have table with 4 rows.
I tried to add like this:
int rowIndex=1;
this.Tables[1].Rows.Add(this.Tables[1].Rows[rowIndex]);
Source. if I set int rowIndex=1;
it adds row to the begining of the table, when I tried to set it to int rowIndex=4;
it adds row to the row before last.
I need a new last row at the end of the table, so I tried int rowIndex=5;
, but then I get :
Unhandled Exception: System.Runtime.InteropServices.COMException: The requested member of the collection does not exist. at Microsoft.Office.Interop.Word.Rows.get_Item(Int32 Index)
回答1:
Try:
object oMissing = System.Reflection.Missing.Value;
this.Tables[1].Rows.Add(ref oMissing);
来源:https://stackoverflow.com/questions/53516251/add-row-to-word-doc-using-c-sharp