第一、二段代码可在foxtable中分别独立运行,但没有衔接好;第三段代码是word中的VBA代码,不知如何加进来,请帮忙,谢谢!
'第一段代码:写入word模板,生成word报表:
Dim clbx1 As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
Dim clbx2 As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox2")
For Each j As String In clbx2.CheckedIndices
Dim tm As String = ProjectPath & "模板文件\" & clbx2.Items(j) '指定模板文件
For Each i As Integer In clbx1.CheckedIndices
Dim fl As String = ProjectPath & "成品文件\" & clbx1.items(i) & clbx2.Items(j) '指定目标文件
'文件已经存在,是否覆盖重新填写
If FileSys.FileExists(fl) Then
If MessageBox.Show(fl & "文件已经存在,是否覆盖重新填写?","提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
Continue For
End If
End If
Dim nm As String = CurrentTable.Name
Dim dr As DataRow =DataTables(nm).Find("名称 = '" & clbx1.items(i) & "'")
'写入模板
If dr IsNot Nothing
Dim wrt As New WordReport(Tables(nm),tm,fl) '定义一个WordReport
wrt.BuildOne(dr)
wrt.quit
End If
Next
Next
'第二段代码,删除生成的word报表中的空行:
Dim app As New MSWord.Application
try
Dim doc = app.Documents.Open("fl")
For Each k As object In doc.Paragraphs
If Len(Trim(k.Range.text)) = 1 Then k.Range.Delete
Next
doc.save
app.quit
catch ex As exception
msgbox(ex.message)
app.quit
End try
'第三段代码,word报表重新排版:
'删除手动换行符和假段落标记----这两句放到删除空行之前,
ActiveDocument.Content.Find.Execute FindText:="^l", replacewith:="^p", Replace:=wdReplaceAll
ActiveDocument.Content.Find.Execute FindText:="^13", replacewith:="^p", Replace:=wdReplaceAll
'取消缩进,重新缩进,
Selection.WholeStory '全选
With Selection.ParagraphFormat '选定区域段落设置
.CharacterUnitFirstLineIndent = 0 '取消首行缩进
.FirstLineIndent = CentimetersToPoints(0)
.CharacterUnitLeftIndent = 2 '左缩进2字符
End With
Selection.HomeKey unit:=wdStory '光标移至文首