我正在尝试将一个表插入到单词的标题中,但不是将其放在标题中,而是在页面正文中创建表
我试过了,
Dim objApp As Word.Application
Dim objDoc As Word.Document
objApp = New Word.Application()
objDoc = objApp.Documents.Open(TextBox1.Text)
objDoc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True
objDoc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Tables.Add(Range:=objApp.Selection.Range, NumRows:=3, NumColumns:=1)
objDoc.Save()
objDoc.Close()
objApp.Quit()
Dim oWord = New Microsoft.Office.Interop.Word.Application
Dim Dir As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
oWord.Documents.Open(TextBox1.Text)
Dim oDoc = oWord.ActiveDocument
oWord.Visible = True
Dim tbl As Word.Table = oDoc.Tables(1)
tbl.Cell(1, 1).Range.Text = "Content"
tbl.Cell(2, 1).Range.Text = "Content"
tbl.Cell(3, 1).Range.Text = "Total Exp:"
oDoc.Save()
oDoc.Close()
oWord.Quit()
任何帮助都将非常感激。
答案 0 :(得分:1)
ojDoc.Sections(1).
Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.
Tables.Add(Range:=objApp.Selection.Range, NumRows:=3, NumColumns:=1)
您正在尝试将新表锚定在选择中,但这可能不在标题内。
这似乎有效:
Dim r As Word.Range = objDoc.Sections(1).
Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range
r.Tables.Add(Range:=r, NumRows:=3, NumColumns:=1)