- Code: Select all
ZWordApplic = New Word.Application
ZWordApplic.Visible = True
ZDocument = ZWordApplic.Documents.Add()
Dim tb1 As Word.Table = ZDocument.Tables.Add(ZWordApplic.Selection.Range, 10, 6)
For i = 1 To 10
For j = 1 To 6
' tb.Columns.Add(CStr(j))
tb1.Rows(i).Cells(j).Range.InsertAfter(CStr(i) + "+" + CStr(j))
Next
Next
ZDocument.SaveAs(Application.StartupPath + "\" + "gogo.docx")
Dim section As Section = ZDocument.Sections(0) ’‘’‘这里报错, 其他信息: 值不在预期的范围内。
Dim table As Table = TryCast(section.Tables(0), Table)
table.ApplyHorizontalMerge(6, 2, 3)
ZDocument.SaveToFile("gogo.docx")
不知道哪里出错,还是新建的文档里没有Sections。请高手指点。