-1

我创建了一个表。该表从文档的第一行开始。我的问题是我不能在表格上方插入一行。每次我尝试添加段落时,段落都会插入到最后一个表格之后。有没有办法在第一个表上方插入 lin ?

为了说明我的问题:

http://www.techrepublic.com/blog/msoffice/insert-a-line-above-a-word-table-at-the-top-of-the-page/846

到目前为止我的代码:

Dim oApp As Word.Application
    Dim oDoc As Word.Document


    oApp = CType(CreateObject("Word.Application"), Word.Application)
    oDoc = oApp.Documents.Add()


    Dim rng As Word.Range = oDoc.Range(0, 0)
    rng.Font.Name = "Verdana"
    rng.Font.Size = 16


    Dim para As Word.Paragraph = oDoc.Paragraphs.Add()
    para.Range.Text = "Factsheet"



    Dim tlb6 As Word.Table = oDoc.Tables.Add(Range:=rng, NumRows:=1, NumColumns:=4)


    Dim CurrentDateTime As Date = Date.Now
    Dim CurrentDate As Date = New Date(CurrentDateTime.Year, CurrentDateTime.Month, CurrentDateTime.Day)

    tlb6.Cell(1, 1).Range.Text = "Date"
    tlb6.Cell(1, 1).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20
    tlb6.Cell(1, 1).Borders.OutsideLineStyle = 1
    tlb6.Cell(1, 2).Range.Text = CurrentDate
    tlb6.Cell(1, 2).Borders.OutsideLineStyle = 1
    tlb6.Cell(1, 3).Range.Text = "Issued by"
    tlb6.Cell(1, 3).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20
    tlb6.Cell(1, 3).Borders.OutsideLineStyle = 1
    tlb6.Cell(1, 4).Range.Text = ""
    tlb6.Cell(1, 4).Borders.OutsideLineStyle = 1
4

2 回答 2

3

如果您使用的是 Word 2010,这应该可以完成工作(虽然它很丑并且使用 Select 和 ActiveDocument):

If ActiveDocument.Paragraphs(1).Range.Information(wdWithInTable) = True Then
    tbl6.Rows(1).Cells(1).Range.Collapse direction:=wdLeft
    Selection.SplitTable
End If

它检查以确保第一个 Paragraph 对象在表格内,如果是,则在其上方添加一行文本。

于 2012-12-07T18:59:42.723 回答
0

根据凯文的回答,一个更清洁的解决方案:

ActiveDocument.Range(0, 0).Select
If Selection.Information(wdWithInTable) = True Then
    Selection.InsertBreak Type:=wdColumnBreak
End If
于 2016-03-29T22:48:43.790 回答