以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]Word报表 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=174983) |
-- 作者:为学日益 -- 发布时间:2022/2/14 14:55:00 -- [求助]Word报表 蓝老师好! 我把表格数据按照【姓名】不同,写入Word模板,表面看着没有问题,但是如果遍历生成的文件夹文件,发现同时生成了一套带前缀“~$”的文件。 在文件夹中显示隐藏文件,也看不到,但是遍历文件可以显示,是什么原因? 代码如下: \'\'\' 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 & "秒") |
-- 作者:有点蓝 -- 发布时间:2022/2/14 15:00:00 -- word文档使用都会有一些临时文件,什么原因要去问微软,我也不知道哦 |