C# 使用Office.Interop将行添加到MS Word表

C# 使用Office.Interop将行添加到MS Word表,c#,ms-word,office-interop,C#,Ms Word,Office Interop,我有一个word模板,其中有一个表,我正在从使用制表符拆分的字符串列表中填充该表 我不知道我将有多少行文字,因为它会有所不同 因此,在遍历循环之前,我以编程方式添加一行,如下所示: oWordDoc.Tables[2].Rows.Add(oWordDoc.Tables[2].Rows[1]); 不幸的是,它是在当前行之前而不是之后添加行 如何将代码更改为始终在当前行之后添加空行?我找到了它,它应该是: Object oMissing = System.Reflection.Missing.Va

我有一个word模板,其中有一个表,我正在从使用制表符拆分的字符串列表中填充该表

我不知道我将有多少行文字,因为它会有所不同

因此,在遍历循环之前,我以编程方式添加一行,如下所示:

oWordDoc.Tables[2].Rows.Add(oWordDoc.Tables[2].Rows[1]);
不幸的是,它是在当前行之前而不是之后添加行


如何将代码更改为始终在当前行之后添加空行?

我找到了它,它应该是:

Object oMissing = System.Reflection.Missing.Value;
oWordDoc.Tables[2].Rows.Add(ref oMissing); 

将参数值保留为行的缺少值。添加函数

object oMissing = System.Reflection.Missing.Value;        
// get your table or create a new one like this
// you can start with two rows. 
Microsoft.Office.Interop.Word.Table myTable = oWordDoc.Add(myRange, 2,numberOfColumns)
int rowCount = 2; 
//add a row for each item in a collection.
foreach( string s in collectionOfStrings)
{
   myTable.Rows.Add(ref oMissing)
   // do somethign to the row here. add strings etc. 
   myTable.Rows.[rowCount].Cells[1].Range.Text = "Content of column 1";
   myTable.Rows[rowCount].Cells[2].Range.Text = "Content of column 2";
   myTable.Rows[rowCount].Cells[3].Range.Text = "Content of column 3";
   //etc
   rowCount++;
}
我还没有测试这个代码,但应该工作