代码改成
Dim tm As String = ProjectPath & "Attachments\通讯录.doc" '指定模板文件
Dim fl As String = ProjectPath & "Reports\通讯录.doc" '指定目标文件
Dim wrt As New WordReport(Tables("成本控制中心"),tm,fl) '定义一个WordReport
Dim sum As Integer
For i As Integer = 0 To Tables("成本控制中心").rows.count - 1
Dim r As Row = Tables("成本控制中心").rows(i)
wrt.ReplaceOne("[@成本控制中心,部门," & (i+1) & "]",r("部门"))
wrt.ReplaceOne("[@成本控制中心,姓名," & (i+1) & "]",r("姓名"))
Next
For i As Integer = Tables("成本控制中心").rows.count to 4
wrt.ReplaceOne("[@成本控制中心,部门," & (i) & "]", "")
wrt.ReplaceOne("[@成本控制中心,姓名," & (i) & "]", "")
Next
wrt.BuildOne(Tables("成本控制中心").rows(0))
wrt.Show() '显示报表