Word文档中表格之间的间距

huangapple go评论61阅读模式
英文:

spacing between Tables in word document

问题

以下是翻译后的代码部分:

'    Set wrdTable1 = objDoc.Tables.Add(objDoc.Range, 20, 2)
    Set wrdTable1 = objDoc.Tables.Add(Range:=objWord.Selection.Range, NumRows:=20, NumColumns:=2, _
         DefaulttableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed)

    wrdTable1.Borders.Enable = False

    With wrdTable1.Rows(1)
        .Cells(1).Range.Text = "Tele: @@@@"
        .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
        .Cells(2).Range.Text = "!@@@@@@##@#"
        .Cells(2).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
    End With

    wrdTable1.Rows(2).Cells(2).Range.Text = "PIN- 9@@@@@"
    wrdTable1.Rows(3).Cells(2).Range.Text = "##########"
    wrdTable1.Rows(20).Cells.Merge
    wrdTable1.Rows(20).Cells(1).Range.Text = "2.   It is under ref :-"
    wrdTable1.Rows(20).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify

    wrdTable1.Range.InsertParagraphAfter

    Set wrdTable2 = objDoc.Tables.Add(wrdTable1.Range.Next, ntotalRecords, ntotalColumns) 
    Dim intRow As Integer
    Dim intCol As Integer

    With wrdTable2

        intCtr = 1: intRow = 1
        While (Sheets("SummaryDVBan").Cells(intCtr, 11).FormulaR1C1 <> "")

            For intCol = 1 To ntotalColumns

                .Cell(intRow, intCol).Range.InsertAfter Sheets("SummaryDVBan").Cells(intCtr, intCol + 10).FormulaR1C1

            Next intCol

        intCtr = intCtr + 1
        intRow = intRow + 1
        Wend

        .Columns(1).SetWidth 40, wdAdjustFirstColumn
        .Columns(2).SetWidth 120, wdAdjustFirstColumn
        .Columns(3).SetWidth 60, wdAdjustFirstColumn
        .Columns(4).SetWidth 90, wdAdjustFirstColumn
        .Columns(5).SetWidth 65, wdAdjustFirstColumn
        .Columns(6).SetWidth 60, wdAdjustFirstColumn
        .Columns(7).SetWidth 90, wdAdjustFirstColumn

        .Style = "Table Grid"
        .Borders.Enable = True
        .Rows(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
        .Rows(1).Range.Bold = True
        .Rows(1).HeadingFormat = True
        .Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
        .Borders.InsideLineStyle = wdLineStyleSingle

    End With
    wrdTable2.Range.InsertParagraphAfter

    Set wrdTable3 = objDoc.Tables.Add(wrdTable2.Range.Next, 7, 4) ' insert table 3
    wrdTable3.Borders.Enable = False

    w = wrdTable3.Rows(1).Cells(1).Width * 4
    w1 = w * 0.26

    For X = 1 To 7
       With wrdTable3.Rows(X)
            .Cells(1).Width = w1
            .Cells(2).Width = w1
            .Cells(3).Width = w1
            .Cells(4).Width = w1
            .Height = 16
        End With
    Next X

    wrdTable3.Rows(1).Cells.Merge
    wrdTable3.Rows(1).Cells(1).Range.Text = "3.   The confirmation at the earliest pl."
    wrdTable3.Rows(1).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
    wrdTable3.Rows(1).Cells(1).Range.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
    wrdTable3.Rows(1).Cells(1).Range.ParagraphFormat.LineSpacing = 18

    

    With objDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range
        .Text = "REQUEST REMINDER"
        .ParagraphFormat.Alignment = wdAlignParagraphCenter
        .Font.Bold = True
        .Font.Name = "Arial"
        .Font.Size = 12
        .Font.Underline = wdUnderlineSingle
        .InsertParagraphAfter
        .ParagraphFormat.SpaceAfter = 12          ' twice the font size for 1 "blank line"
    End With

End Sub

以上是代码的翻译,没有包括任何其他内容。如果您有其他问题或需要进一步的协助,请随时提出。

英文:
&#39;    Set wrdTable1 = objDoc.Tables.Add(objDoc.Range, 20, 2)
Set wrdTable1 = objDoc.Tables.Add(Range:=objWord.Selection.Range, NumRows:=20, NumColumns:=2, _
DefaulttableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed)
wrdTable1.Borders.Enable = False
With wrdTable1.Rows(1)
.Cells(1).Range.Text = &quot;Tele: @@@@&quot;
.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Cells(2).Range.Text = &quot;!@@@@@@##@#&quot;
.Cells(2).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
End With
wrdTable1.Rows(2).Cells(2).Range.Text = &quot;PIN- 9@@@@@&quot;
wrdTable1.Rows(3).Cells(2).Range.Text = &quot;##########&quot;
wrdTable1.Rows(20).Cells.Merge
wrdTable1.Rows(20).Cells(1).Range.Text = &quot;2.   It is under ref :-&quot;
wrdTable1.Rows(20).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
wrdTable1.Range.InsertParagraphAfter
Set wrdTable2 = objDoc.Tables.Add(wrdTable1.Range.Next, ntotalRecords, ntotalColumns) 
Dim intRow As Integer
Dim intCol As Integer
With wrdTable2
intCtr = 1: intRow = 1
While (Sheets(&quot;SummaryDVBan&quot;).Cells(intCtr, 11).FormulaR1C1 &lt;&gt; &quot;&quot;)
For intCol = 1 To ntotalColumns
.cell(intRow, intCol).Range.InsertAfter Sheets(&quot;SummaryDVBan&quot;).Cells(intCtr, intCol + 10).FormulaR1C1
Next intCol
intCtr = intCtr + 1
intRow = intRow + 1
Wend
.Columns(1).SetWidth 40, wdAdjustFirstColumn
.Columns(2).SetWidth 120, wdAdjustFirstColumn
.Columns(3).SetWidth 60, wdAdjustFirstColumn
.Columns(4).SetWidth 90, wdAdjustFirstColumn
.Columns(5).SetWidth 65, wdAdjustFirstColumn
.Columns(6).SetWidth 60, wdAdjustFirstColumn
.Columns(7).SetWidth 90, wdAdjustFirstColumn
.Style = &quot;Table Grid&quot;
.Borders.Enable = True
.Rows(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Rows(1).Range.Bold = True
.Rows(1).HeadingFormat = True
.Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
.Borders.InsideLineStyle = wdLineStyleSingle
End With
wrdTable2.Range.InsertParagraphAfter
Set wrdTable3 = objDoc.Tables.Add(wrdTable2.Range.Next, 7, 4) &#39; insert table 3
wrdTable3.Borders.Enable = False
w = wrdTable3.Rows(1).Cells(1).Width * 4
w1 = w * 0.26
For X = 1 To 7
With wrdTable3.Rows(X)
.Cells(1).Width = w1
.Cells(2).Width = w1
.Cells(3).Width = w1
.Cells(4).Width = w1
.Height = 16
End With
Next X
wrdTable3.Rows(1).Cells.Merge
wrdTable3.Rows(1).Cells(1).Range.Text = &quot;3.   The confirmation at the earliest pl.&quot;
wrdTable3.Rows(1).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
wrdTable3.Rows(1).Cells(1).Range.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
wrdTable3.Rows(1).Cells(1).Range.ParagraphFormat.LineSpacing = 18
With objDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range
.Text = &quot;REQUEST REMINDER&quot;
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Font.Bold = True
.Font.Name = &quot;Arial&quot;
.Font.Size = 12
.Font.Underline = wdUnderlineSingle
.InsertParagraphAfter
.ParagraphFormat.SpaceAfter = 12          &#39; twice the font size for 1 &quot;blank line&quot;
End With
End Sub

the above code adds three tables into the word document however, the output document is showing the first two tables as joint. Also the when the table2 is spilling over the next page the output word document has the first table being repeated again on the second page. the first table is also being shown with gridlines despite the gridlines set as false.

In the output first and third table is to be without gridlines. first and second table needs to have space between them. the second table is with gridlines. and the first table is not required to repeat itself

答案1

得分: 0

请看以下代码的中文翻译:

' 使用文档插入段落和分节符,并使用文档引用范围以添加下一个表格
objDoc.Paragraphs.Last.Range.InsertParagraphAfter
objDoc.Paragraphs.Last.Range.InsertBreak Type:=wdSectionBreakContinuous
Dim rng As Range
Set rng = objDoc.Range(objDoc.Paragraphs.Last.Range.Start, objDoc.Paragraphs.Last.Range.End)
Set wrdTable2 = objDoc.Tables.Add(rng, ntotalrecords, ntotalColumns)
Dim intRow As Integer
Dim intCol As Integer
英文:

Use the document to insert the paragraph and a section break, and also use the document to reference the range to add the next table

    objDoc.Paragraphs.Last.Range.InsertParagraphAfter
objDoc.Paragraphs.Last.Range.InsertBreak Type:=wdSectionBreakContinuous
Dim rng As Range
Set rng = objDoc.Range(objDoc.Paragraphs.Last.Range.Start, objDoc.Paragraphs.Last.Range.End)
Set wrdTable2 = objDoc.Tables.Add(rng, ntotalrecords, ntotalColumns)
Dim intRow As Integer
Dim intCol As Integer

huangapple
  • 本文由 发表于 2023年2月18日 01:37:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75487556.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定