【问题标题】:Update cells in tables in header in word document using vb.net使用 vb.net 更新 word 文档标题中表格中的单元格
【发布时间】:2015-06-26 11:47:22
【问题描述】:

我在 vb.net 中打开了一个 word 文档。这个word文档在标题和文档中都有表格。 我尝试更新文档中的表格,它工作正常。但无法成功更新表头中的表。需要帮助了解更新表头中的表的语法。

'update table
Dim r As Integer, c As Integer
oTable = oDoc.Tables(1)
oTable.Range.ParagraphFormat.SpaceAfter = 6
For r = 1 To 1
For c = 1 To 4
oTable.Cell(r, c).Range.Text = "r" & r & "c" & c
Next
Next

'update table in header
Dim footerRange As Word.Range = oDoc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Tables
footerRange.Cells(1).Range.Text = "RR"

错误:

请求的集合成员不存在。

在:

Dim footerRange As Word.Range = oDoc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range‌​.Tables(1)

感谢和问候 湿婆.P

【问题讨论】:

  • 在下面的行中有一条错误消息“集合的请求成员不存在。” '更新表头 Dim footerRange As Word.Range = oDoc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Tables(1)
  • 该错误只是表示您引用的索引不存在 Sections(1) 或 Tables (1) 是要引用的不正确索引
  • 如何解决这个问题?

标签: vb.net visual-studio-2012


【解决方案1】:

WdHeaderFooterIndex.wdHeaderFooterFirstPage 仅在您将文档设置为在第一页上具有不同页眉时才有效,如果您的表格在所有页眉中,则在尝试访问 .Tables(1) 时它会崩溃

因此,如果您的表格位于文档中的所有标题中,请使用 WdHeaderFooterIndex.wdHeaderFooterPrimary 作为标题的索引

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-28
    • 2021-10-16
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多