'''
'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) '指定目标文件
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
Dim app As New MSWord.Application
try
Dim doc = app.Documents.Open(fl)
doc.Content.Find.Execute(FindText:="^l", replacewith:="^p", Replace:=2)
doc.Content.Find.Execute(FindText:="^13", replacewith:="^p", Replace:=2)
For Each k As object In doc.Paragraphs
k.Range.Select
If Len(k.Range.text) = 1 Then k.Range.Delete
Do
If app.Selection.Characters(1).Text = Chr(10) Then app.Selection.Characters(1).Delete
Loop Until app.Selection.Characters(1).Text <> Chr(10)
Next
'删除表格空行:
Dim tb As Object, r As Object
With Doc
Dim c1 As object
Dim c2 As object
Dim text As String
For Each tb In .Tables
Dim count As Integer = 0
For Each r In tb.Rows
c1 = r.Cells(2)
text = doc.Range(c1.Range.Start, c1.Range.End - 1).Text
If len(text) = 0 Then
r.Delete
End If
Next
Dim dict As new Dictionary(of Integer, object)
Dim lst As new List(of String)
For i2 As Integer = 1 To tb.Range.cells.count
c1 = tb.Range.cells(i2)
If c1.ColumnIndex = 1 Then
dict.Add(i2,c1)
lst.Add(i2)
End If
Next
c1 = dict(lst(lst.Count -1))
text = doc.Range(c1.Range.Start, c1.Range.End - 1).Text
For j2 As Integer = lst.Count -2 To 0 Step -1
c2 = dict(lst(j2))
Dim txt = doc.Range(c2.Range.Start, c2.Range.End - 1).Text
If txt = text Then
c2.Merge(c1)
c2.Range.Text = text
Else
text = txt
End If
c1 = c2
Next
Next
End With
doc.save
app.quit
catch ex As exception
msgbox(ex.message)
app.quit
End try
End If
Next
Next
'提示窗口:是否查看
Dim Result As DialogResult
Result = MessageBox.Show("文书生成完毕!"& vbcrlf &"是---查看"& vbcrlf &"否---退出", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
Dim Proc As New Process
Proc.File = ProjectPath & "\成品文件"
proc.start
Forms("生成文书").Close()
Else
Forms("生成文书").Close()
End If