比较两个word文档&找不到。省略,缺失,添加单词 [英] Compare two word document & Find no. of omitted,missing, added word

查看:61
本文介绍了比较两个word文档&找不到。省略,缺失,添加单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比较两个word文档&找不到。省略,缺失,添加单词





编辑 [从其他重复问题复制源代码 - Sascha Lefèvre]:

Compare two word document & Find no. of omitted,missing, added word


Edit [copied source code over from otherwise duplicate question - Sascha Lefèvre]:

Dim c As Integer = doc2.Sentences(1).Words.Count
                        Dim c1 As Integer = doc1.Sentences(1).Words.Count - 1
                        'Dim c1 As Integer = doc1.Sentences(2).Words.Count - 1
                        If c1 > c Then
                            b = 1
                            MsgBox("First")
                            For a = 1 To c - 1
                                'MsgBox(doc1.Sentences(1).Words(b).Text.Trim(" ").ToString() & "*****" & doc2.Sentences(1).Words(a).Text.ToString() & "*****")
                                If doc1.Sentences(1).Words(b).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(a).Text.Trim(" ").ToString() Then

                                    b = b + 1
                                    If doc1.Sentences(1).Words(b).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(a).Text.Trim(" ").ToString() And doc1.Sentences(1).Words(b + 1).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(a).Text.Trim(" ").ToString() Then
                                        mistake = mistake + 1
                                        b = b - 1
                                    Else
                                        added = added + 1
                                        b = b + 1
                                    End If
                                Else
                                    b = b + 1
                                End If
                            Next
                            If added = 0 Then
                                added = added + 1
                            End If
                        ElseIf c1 < c Then
                            b = 1
                            MsgBox("Second")
                            For a = 1 To c - 1
                                'MsgBox(doc1.Sentences(1).Words(b).Text.Trim(" ").ToString() & "*****" & doc2.Sentences(1).Words(a).Text.ToString() & "*****")
                                If doc1.Sentences(1).Words(a).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(b).Text.Trim(" ").ToString() Then

                                    b = b + 1
                                    If doc1.Sentences(1).Words(a).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(b).Text.Trim(" ").ToString() And doc1.Sentences(1).Words(a).Text.Trim(" ").ToString() <> doc2.Sentences(1).Words(b + 1).Text.Trim(" ").ToString() Then
                                        mistake = mistake + 1
                                        b = b - 1
                                    Else
                                        omitted = omitted + 1
                                        b = b + 1
                                    End If
                                Else
                                    b = b + 1
                                End If
                            Next
                            
                        Else
                            MsgBox("Third")

                            For a = 1 To c
                                If doc1.Sentences(1).Words(a).Text <> doc2.Sentences(2).Words(a).Text Then

                                    mistake = mistake + 1
                                End If
                            Next
                        End If

                        MsgBox("Mistake " & mistake & " Omitted " & omitted & " Added " & added)

推荐答案

我会用内置的功能,让Word跟踪更改并进行比较。要使用Word中的这些功能,您需要使用Interop。有关示例,请查看演练:从Microsoft Office程序集嵌入类型信息(C#和Visual Basic) [ ^ ]。这个例子适用于Excel,但想法是一样的。



要打开和关闭轨道更改,请参阅_Document.TrackRevisions属性(Microsoft.Office.Interop.Word) [ ^ ]并进行比较,请参阅 _Application.CompareDocuments方法(Microsoft .Office.Interop.Word) [ ^ ]
I would use the built-in functionality in and let the Word to track the changes and do the comparison. To use those abilities from Word you'd need to use Interop. For an example, have a look at Walkthrough: Embedding Type Information from Microsoft Office Assemblies (C# and Visual Basic)[^]. The example is for Excel, but the idea is the same.

To toggle the track changes on and off, see _Document.TrackRevisions property (Microsoft.Office.Interop.Word)[^] and to do the comparison, see _Application.CompareDocuments method (Microsoft.Office.Interop.Word)[^]


这篇关于比较两个word文档&amp;找不到。省略,缺失,添加单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆