Dim t = Tables("表A")
Dim cname = "第一列"
Dim app As New MSWord.Application
try
Dim doc = app.Documents.add
app.Selection.font.Size = 20 '字号
app.Selection.font.Bold = True '加粗
app.Selection.TypeText(Text:="xxx系统表结构" & vbcrlf)
app.Selection.font.Size = 9 '字号
app.Selection.font.Bold = False
For k As Integer = 0 To t.Rows.count-1
If t.Rows(k).IsNull(cname) = False Then
app.Selection.TypeText(Text:=t.Rows(K)(cname) & vbcrlf)
Dim tb = doc.Tables.Add(Range:=app.Selection.Range,NumRows:=1, NumColumns:= t.Cols.Count-1)
With tb
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
.Style = "网格型"
End With
For Each dc As Col In t.Cols
If dc.name <> cname Then
app.Selection.TypeText(Text:=dc.Name)
Dim i As Double
If Double.TryParse(dc.name,i)
app.Selection.ParagraphFormat.Alignment = 2
Else
app.Selection.ParagraphFormat.Alignment = 1
End If
app.Selection.MoveRight(Unit:=12)
End If
Next
For i As Integer = k To t.rows.count-1
Application.doevents
Dim dr As Row = t.rows(i)
If i > K AndAlso t.Rows(i).IsNull(cname) = False Then
k = i-1
app.Selection.MoveRight(Unit:=1,count:=1)
app.ActiveWindow.Selection.TypeParagraph
app.Selection.MoveRight(Unit:=1,count:=1)
app.ActiveWindow.Selection.TypeParagraph
Exit For
ElseIf i>k Then
app.Selection.MoveRight(Unit:=12)
End If
output.show(i)
For j As Integer = 0 To t.Cols.count - 1
Dim dc As Col = t.Cols(j)
If dc.name <> cname Then
app.Selection.TypeText(Text:=dr(dc.Name))
Dim d As Double
If Double.TryParse(dr(dc.name),d)
app.Selection.ParagraphFormat.Alignment = 2
Else
app.Selection.ParagraphFormat.Alignment = 1
End If
If j = t.cols.count-1
Else
app.Selection.MoveRight(Unit:=12)
End If
End If
Next
Next
End If
Next
app.visible = True
catch ex As exception
msgbox(ex.message)
app.Quit
finally
End try