//获取差异
DifferRevisions differRevisions = new DifferRevisions(doc1);
var insetRevisionsList = differRevisions.InsertRevisions;
var deletRevisionsList = differRevisions.DeleteRevisions;
C#新手 ,我的问题是,获取差异后,怎么显示呢,返回是一个list,包含的对象是DocumentObject,
我应该怎么在页面输出差异,直接不知道应该.啥了
遍历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();
}
}
}
遇事不决转json。
解决思路:先把脚本输出,再检查js的语法。