以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]请老师看看哪里错了  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=116122)

--  作者:天一生水
--  发布时间:2018/3/20 11:37:00
--  [求助]请老师看看哪里错了

如图,上传文件后,处理单元格内容。

单独粘贴附件中红色文本,没有问题;

上传文件,根据提取的单元格文本处理时,报错。

请老师看看哪里出问题了,谢谢!

 


图片点击可在新窗口打开查看此主题相关图片如下:image 1.jpg
图片点击可在新窗口打开查看
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:测试.rar


--  作者:有点甜
--  发布时间:2018/3/20 12:26:00
--  

datacolchanged事件,写代码

 

        For i As Integer = 0 To ary.length-1
            str = ary(i).trim
()


--  作者:天一生水
--  发布时间:2018/3/21 20:14:00
--  

甜老师好,我换了一种提取方式,先确定两个段落位置,再提取两段之间的内容。

虽然没报错,但没反应。

BeforeAttachFile代码如下,请老师帮忙看一下,谢谢!

 

Select Case e.DataCol.Name
    Case "上传文件"
        Dim app As New MSWord.Application
        try
            Dim doc = app.Documents.Open(file)
            Dim count = Doc.Characters.Count
            Dim rng As MSWord.Range = Doc.Range(Start:=0, End:=count)
            \'msgbox(rng.Text)
            Dim str As String = rng.text
            \'-----------------------
            Dim ary() = str.replace(chr(10), "").split(new Char() {chr(13),chr(11)})      \'清除段落空行
            Dim ls As new List(Of String)
            For Each s As String In ary
                If s.trim() > "" Then
                    ls.add(s)
                    If s.Contains("长:下面查明当事人和诉讼参与人身份") Then
                        Dim i1 = ls.Indexof(s)                                  \'获取开始段落位置
                       
                        If s.Contains("长:被告报告你的单位名称") Then
                            Dim i2 = ls.Indexof(s)                              \'获取结束段落位置
                           
                            Dim nstr As String = ""
                            For i As Integer = i1 +1 To i2 -1                   \'显示开始-结束之间段落
                                nstr = nstr & ls(i) & vbcrlf
                               
                                e.DataRow("庭审笔录_原告出庭") = nstr
                            Next
                            Exit For
                        End If
                    End If
                End If
            Next
            app.Quit
        catch ex As exception
            msgbox(ex.message)
            app.Quit
        End try
End Select


--  作者:有点甜
--  发布时间:2018/3/21 20:39:00
--  

合成的nstr是否正确?弹出看看

 

                            Dim nstr As String = ""
                            For i As Integer = i1 +1 To i2 -1                   \'显示开始-结束之间段落
                                nstr = nstr & ls(i) & vbcrlf
                            Next

                            msgbox(nstr)

                            e.DataRow("庭审笔录_原告出庭") = nstr

 

然后再在datacolchanged事件,加入msgbox,弹出能否进入执行各个代码了


--  作者:天一生水
--  发布时间:2018/3/21 20:56:00
--  

运行到这句,后面的代码没有运行:

 

......

Dim i1 = ls.Indexof(s)                                  \'获取开始段落位置

 

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:测试.rar

[此贴子已经被作者于2018/3/21 21:45:33编辑过]

--  作者:有点甜
--  发布时间:2018/3/21 22:58:00
--  

\'\'\'
Dim dr As DataRow = e.DataRow
Dim file = e.SourceFolder & "\\" & e.filename
If dr.IsNull("案号") Then
    MessageBox.Show("案号不能为空!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    e.Cancel = True
Else
    Select Case e.DataCol.Name
        Case "上传文件"
            e.FileName = dr("案号") & ".doc"
    End Select
End If

Select Case e.DataCol.Name
    Case "上传文件"
        Dim app As New MSWord.Application
        try
            Dim doc = app.Documents.Open(file)
            Dim count = Doc.Characters.Count
            Dim rng As MSWord.Range = Doc.Range(Start:=0, End:=count)
            \'msgbox(rng.Text)
            Dim str As String = rng.text
            \'-----------------------
            Dim ary() = str.replace(chr(10), "").split(new Char() {chr(13),chr(11)})      \'清除段落空行
            Dim ls As new List(Of String)
            Dim i1 = -1
            Dim i2 = -1
            For Each s As String In ary
                If s.trim() > "" Then
                    ls.add(s)
                    If s.Contains("被告报告你的单位名称") Then
                        i1 = ls.count-1
                    End If
                    If s.Contains("原告对被告出庭人员有无异议") Then
                        i2 = ls.count-1
                    End If
                End If
            Next
            Dim nstr As String = ""
            For i As Integer = i1 +1 To i2 -1                   \'显示开始-结束之间段落
                nstr = nstr & ls(i) & vbcrlf
            Next
            msgbox(nstr)
           
            e.DataRow("被告") = nstr
            app.Quit
        catch ex As exception
            msgbox(ex.message)
            app.Quit
        End try
End Select


--  作者:天一生水
--  发布时间:2018/3/22 11:45:00
--  

老师,又遇到一个情况,有一段“第三人”的文字可能存在,也可能不存在。怎样判断?

........
Dim i1 = -1
Dim i2 = -1
Dim i3 = -1                                                                          \'第三人开始位置,不一定存在
Dim i4 = -1
For Each s As String In ary
    If s.trim() > "" Then
        ls.add(s)
        If s.Contains("下面查明当事人和诉讼参与人身份") Then                         \'原告位置
            i1 = ls.count-1
        End If
        If s.Contains("被告报告") AndAlso s.Contains("法定代表人姓名") Then    \'被告位置
            i2 = ls.count-1
        End If
        If s.Contains("第三人报告") AndAlso s.Contains("情况") Then               \'第三人位置,不一定存在
            i3 = ls.count-1
        End If
        If s.Contains("原告对") AndAlso s.Contains("有无异议") Then               \'结束位置
            i4 = ls.count-1
        End If
    End If
Next


If i3 >=1 Then                                                       \'如果第三人存在
   
    Dim nstr As String = ""                                                                    \'显示原告出庭段落
    For i As Integer = i1 +1 To i2 -1
        nstr = nstr & ls(i) & vbcrlf
    Next
    e.DataRow("庭审笔录_原告出庭") = nstr
   
    Dim nstr1 As String = ""                                                                   \'显示被告出庭段落
    For i As Integer = i2 +1 To i3 -1
        nstr1 = nstr1 & ls(i) & vbcrlf
    Next
    e.DataRow("庭审笔录_被告出庭") = nstr1
   
    Dim nstr2 As String = ""                                                                   \'显示第三人出庭段落
    For i As Integer = i3 +1 To i4 -1
        nstr2 = nstr2 & ls(i) & vbcrlf
    Next
    e.DataRow("庭审笔录_第三人出庭") = nstr2
   
Else                                                                     \'第三人不存在
    
    Dim nstr As String = ""                                                                     \'显示原告出庭段落
    For i As Integer = i1 +1 To i2 -1
        nstr = nstr & ls(i) & vbcrlf
    Next
    e.DataRow("庭审笔录_原告出庭") = nstr
   
    Dim nstr1 As String = ""                                                                    \'显示被告出庭段落
    For i As Integer = i2 +1 To i4 -1
        nstr1 = nstr1 & ls(i) & vbcrlf
    Next
    e.DataRow("庭审笔录_被告出庭") = nstr1
   
End If

.............


--  作者:有点甜
--  发布时间:2018/3/22 12:06:00
--  
If i3 = -1 Then   \'不存在的情况