首页 新闻 会员 周边 捐助

c# Spire.Doc插件 获取两个word间的差异

0
悬赏园豆:50 [已解决问题] 解决于 2022-09-05 08:03

//获取差异
DifferRevisions differRevisions = new DifferRevisions(doc1);
var insetRevisionsList = differRevisions.InsertRevisions;
var deletRevisionsList = differRevisions.DeleteRevisions;

C#新手 ,我的问题是,获取差异后,怎么显示呢,返回是一个list,包含的对象是DocumentObject,

我应该怎么在页面输出差异,直接不知道应该.啥了

头一回的主页 头一回 | 初学一级 | 园豆:21
提问于:2022-09-02 14:57
< >
分享
最佳答案
0

遍历list,判断list里面的项是不是TextRange,如果是,把它强制转换为TextRange,然后通过TextRange.Text属性获取差异.

using Spire.Doc;
using Spire.Doc.Fields;
using System;

namespace GetDifferencesInList
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load one Word document
            Document doc1 = new Document("C:\\Users\\Administrator\\Desktop\\original.docx");

            //Load the other Word document
            Document doc2 = new Document("C:\\Users\\Administrator\\Desktop\\revised.docx");

            //Compare the two Word documents
            doc1.Compare(doc2, "Author");

            //Get the revisions
            DifferRevisions differRevisions = new DifferRevisions(doc1);

            //Return the insertion revisions in a list
            var insetRevisionsList = differRevisions.InsertRevisions;

            //Return the deletion revisions in a list
            var deletRevisionsList = differRevisions.DeleteRevisions;

            //Create two int variables
            int m = 0;
            int n = 0;

            //Loop through the insertion revision list 
            for (int i = 0; i < insetRevisionsList.Count; i++)
            {
                if (insetRevisionsList[i] is TextRange)
                {
                    m += 1;
                    //Get the specific revision and get its content
                    TextRange textRange = insetRevisionsList[i] as TextRange;
                    Console.WriteLine("Insertion #" + m + ":" + textRange.Text);
                }
            }
            Console.WriteLine("=====================");

            //Loop through the deletion revision list 
            for (int i = 0; i < deletRevisionsList.Count; i++)
            {
                if (deletRevisionsList[i] is TextRange)
                {
                    n += 1;
                    //Get the specific revision and get its content
                    TextRange textRange = deletRevisionsList[i] as TextRange;
                    Console.WriteLine("Deletion #" + n + ":" + textRange.Text);
                }
            }
            Console.ReadKey();
        }
    }
}
收获园豆:50
ms_doudou | 小虾三级 |园豆:1170 | 2022-09-02 17:54
其他回答(2)
0

遇事不决转json。

ensleep | 园豆:1682 (小虾三级) | 2022-09-02 14:58
0

解决思路:先把脚本输出,再检查js的语法。

苍洱孤鸿 | 园豆:215 (菜鸟二级) | 2022-09-02 17:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册