Dim app
As New MSWord.Application |
try |
Dim doc = app.Documents.Open(tm) |
If
app.ActiveWindow.Selection.Find.Execute("[" & bm & "附表]") Then |
'插入表格,方法1或2 |
Dim dt2 As DataTable = dttable |
doc.Tables.Add(Range:=app.Selection.Range,NumRows:=1, NumColumns:=
dt2.DataCols.Count) |
With app.Selection.Tables(1) |
.ApplyStyleHeadingRows = True |
.ApplyStyleLastRow = True |
.ApplyStyleFirstColumn = True |
.ApplyStyleLastColumn = True |
.Style = "网格型" |
End With |
For Each dc As DataCol In
dt2.DataCols |
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) |
Next |
For i As Integer = 0 To
dt.rows.count-1 |
Dim dr As Row = dt.rows(i) |
|
For j As Integer = 0 To
dt.cols.count - 1 |
Dim dc As Col =
dt.cols(j) |
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 i = dt.rows.count-1
AndAlso j = dt.cols.count-1 |
Else |
app.Selection.MoveRight(Unit:=12) |
End If |
Next |
|
Next |
End If |
app.Documents(tm).save |
app.quit |
catch ex As exception |
app.Quit |
finally |
End try |