vb.net应用程序中向word表动态添加行

vb.net应用程序中向word表动态添加行,vb.net,Vb.net,我运行此代码是为了在vb.net中打开word文档 Dim oWord_detail As New word.Application Dim oDoc_detail As word.Document oWord_detail.Visible = True oDoc_detail = oWord_detail.Documents.Open("c:\integra-billing\integra-invoice-detail.docx", False, False) 然后,我使用这一行将新行添加到

我运行此代码是为了在vb.net中打开word文档

Dim oWord_detail As New word.Application
Dim oDoc_detail As word.Document
oWord_detail.Visible = True
oDoc_detail = oWord_detail.Documents.Open("c:\integra-billing\integra-invoice-detail.docx", False, False)
然后,我使用这一行将新行添加到word文档中

oDoc_detail.Tables(1).Rows.Add()
但当它运行时,上面的一行显示错误:

The requested member of the collection does not exist
如果表已经存在,请尝试 oDoc_detail.Tables.Item1.Rows.Add

然后将文本添加到单元格

Dim oWord_detail As New Word.Application
Dim oDoc_detail As Word.Document
oWord_detail.Visible = True
oDoc_detail = oWord_detail.Documents.Open("C:\Dati\Temp\test.docx", False, False)
oDoc_detail.Tables.Item(1).Rows.Add()

For r = 1 To 1  'your row
For c = 1 To 3
oDoc_detail.Tables.Item(1).Cell(r, c).Range.Text = "r" & r & "c" & c
Next
Next

有一个表,我必须给它命名吗?或者给它一个ID或其他东西?我的word表在一个文本框中,如果这有区别的话?好的,它从文本框中出来,现在可以工作了。我的表中有3列,如何向每列添加数据?如何向单元格添加数据/文本?