Add row to word doc using C# [duplicate]

纵然是瞬间 提交于 2021-01-27 22:00:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!