Dim tm As String = ProjectPath & "Attachments\中院明传.doc" '指定模板文件
Dim fl As String = ProjectPath & "Reports\" & Format(Date.now,"yyyyMMddHHmmss") & "中院明传.doc" '指定目标文件
FileSys.CopyFile(tm, fl,True)
'Dim ps As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("WinWord")
'For Each p As System.Diagnostics.Process In ps
'p.kill ’杀进程
'Next
Dim app As New MSWord.Application
try
Dim doc = app.Documents.Open(fl)
e.Form.Controls("But01").PerformClick() ’模拟点击按钮,生成统计表1
If app.ActiveWindow.Selection.Find.Execute("表1") Then
'插入表格,方法1或2
Dim dt As DataTable = Tables("质效分析_Table1").DataTable
doc.Tables.Add(Range:=app.Selection.Range,NumRows:=1, NumColumns:= dt.DataCols.Count)
With app.Selection.Tables(1)
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
.Style = "网格型"
End With
For Each dc As DataCol In dt.DataCols
app.Selection.TypeText(Text:=dc.Name)
app.Selection.MoveRight(Unit:=12)
Next
For Each dr As DataRow In dt.DataRows
For Each dc As DataCol In dt.DataCols
app.Selection.TypeText(Text:=dr(dc.Name))
app.Selection.MoveRight(Unit:=12)
Next
Next
End If
'Application.DoEvents
e.Form.Controls("But02").PerformClick()
If app.ActiveWindow.Selection.Find.Execute("表2") Then
'插入表格,方法1或2
Dim dt As DataTable = Tables("质效分析_Table1").DataTable
doc.Tables.Add(Range:=app.Selection.Range,NumRows:=1, NumColumns:= dt.DataCols.Count)
With app.Selection.Tables(1)
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
.Style = "网格型"
End With
For Each dc As DataCol In dt.DataCols
app.Selection.TypeText(Text:=dc.Name)
app.Selection.MoveRight(Unit:=12)
Next
For Each dr As DataRow In dt.DataRows
For Each dc As DataCol In dt.DataCols
app.Selection.TypeText(Text:=dr(dc.Name))
app.Selection.MoveRight(Unit:=12)
Next
Next
End If
'Application.DoEvents
app.Visible = True
catch ex As exception
msgbox(ex.message)
app.Quit
finally
End try
此主题相关图片如下:截屏图片 (2).jpg