'''
Dim st As Date = Date.Now
Dim nd As String= e.Form.Controls("ComboBox1").Value '年度
Dim xm As String '姓名
Dim xb As String '性别
Dim csrq As Date '出生日期
Dim rdsj As Date '入党时间
Dim nddf As Integer '年度得分
Dim pddc As String '评定等次
Dim dzz As String ="中共济南市历城区西营镇西营办事处秦口峪村党支部" '党组织
Dim sj As Date = Date.today '时间
Dim zrs As Integer '总人数
Dim i0 As Integer '遍历人数
Dim Filter As String
Filter = Tables("农村党员积分考核公示_table1").Filter
Dim Products As List(Of String)
Products = Tables("农村党员积分考核公示_table1").DataTable.GetValues("姓名",Filter,"月度")
zrs = Products.Count
For Each Product As String In Products
xm = Product '姓名
i0+=1
Dim tm As String = ProjectPath & "Attachments\党员积分台账表.docx" '指定模板文件
Dim fl As String = ProjectPath & "Attachments\党员积分台账表\" & nd & "\" & Product & ".docx" '指定目标文件
FileSys.CopyFile(tm, fl,True)
Dim ps As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcesses() '清理Word进程
For Each p As System.Diagnostics.Process In ps
If ("WINWORD" = p.ProcessName)
p.kill
End If
Next
Dim app As New MSWord.Application
try
Dim doc = app.Documents.Open(fl)
Dim t = doc.Tables(1) 'word文档中的第1个表
Dim i As Integer = 0 '12个月
Dim Filter0 As String = "[姓名] = '" & Product & "'"
Dim drs As List(Of DataRow) = Tables("农村党员积分考核公示_table1").DataTable.Select(Filter0,"月度")
For Each dr As DataRow In drs
i+=1
e.Form.Controls("Label2").text = "正在写入" & i0 & "/" & zrs & " " & dr("姓名") & "......"
t.Cell(i+3,3).Range.Text = dr("实际得分_5") '单元格的值
t.Cell(i+3,4).Range.Text = dr("实际得分_2") '单元格的值
t.Cell(i+3,5).Range.Text = dr("实际得分_4") '单元格的值
t.Cell(i+3,6).Range.Text = dr("实际得分_3") '单元格的值
t.Cell(i+3,7).Range.Text = dr("实际得分_1") '单元格的值
nddf = nddf + dr("实际得分_4")+ dr("实际得分_1")+ dr("实际得分_3")+ dr("实际得分_2")+dr("实际得分_5")
Next
t.Cell(16,2).Range.Text = Format(nddf/12, "#")
'***************文字替换
app.Selection.Find.Text = "[年度]"
app.Selection.Find.Replacement.ClearFormatting()
app.Selection.Find.Replacement.Text = nd
app.Selection.Find.Execute(Replace:=MSWord.WdReplace.wdReplaceAll)
app.Selection.Find.Text = "[党组织]"
app.Selection.Find.Replacement.ClearFormatting()
app.Selection.Find.Replacement.Text = dzz
app.Selection.Find.Execute(Replace:=MSWord.WdReplace.wdReplaceAll)
app.Selection.Find.Text = "[时间]"
app.Selection.Find.Replacement.ClearFormatting()
app.Selection.Find.Replacement.Text = sj
app.Selection.Find.Execute(Replace:=MSWord.WdReplace.wdReplaceAll)
app.Selection.Find.Text = "[姓名]"
app.Selection.Find.Replacement.ClearFormatting()
app.Selection.Find.Replacement.Text = Product
app.Selection.Find.Execute(Replace:=MSWord.WdReplace.wdReplaceAll)
doc.save
app.Quit
catch ex As exception
msgbox(ex.message)
app.Quit
finally
End try
gc.Collect
Next
Dim Proc As New Process '定义一个新的Process
Proc.File = ProjectPath & "Attachments\党员积分台账表\" & nd & "\" '指定要打开的文件
Proc.Start()
e.Form.Controls("Label2").text = ""
MessageBox.Show("写入党员积分台账表" & Products.Count & "份,共耗时: " & (Date.Now - st).TotalSeconds & "秒")
此主题相关图片如下:截屏图片 (1).jpg