本文整理汇总了C#中Document.Compare方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Compare方法的具体用法?C# Document.Compare怎么用?C# Document.Compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.Compare方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compare
/// <summary>
/// Compare the two documents using Aspose.Words and save the result as a Word document
/// </summary>
/// <param name="document1">First document</param>
/// <param name="document2">Second document</param>
/// <param name="comparisonDocument">Comparison document</param>
public void Compare(string document1, string document2, string comparisonDocument, ref int added, ref int deleted)
{
added = 0;
deleted = 0;
// Load both documents in Aspose.Words
Document doc1 = new Document(document1);
Document doc2 = new Document(document2);
Document docComp = new Document(document1);
DocumentBuilder builder = new DocumentBuilder(docComp);
doc1.Compare(doc2, "a", DateTime.Now);
foreach (Revision revision in doc1.Revisions)
{
switch (revision.RevisionType)
{
case RevisionType.Insertion:
added++;
break;
case RevisionType.Deletion:
deleted++;
break;
}
Console.WriteLine(revision.RevisionType + ": " + revision.ParentNode);
}
Debug.WriteLine("Revisions: " + doc1.Revisions.Count);
doc1.Save(comparisonDocument);
}
示例2: NormalComparison
private static void NormalComparison(string dataDir)
{
// ExStart:NormalComparison
Document docA = new Document(dataDir + "TestFile.doc");
Document docB = new Document(dataDir + "TestFile - Copy.doc");
// DocA now contains changes as revisions.
docA.Compare(docB, "user", DateTime.Now);
// ExEnd:NormalComparison
}
示例3: CompareForEqual
private static void CompareForEqual(string dataDir)
{
// ExStart:CompareForEqual
Document docA = new Document(dataDir + "TestFile.doc");
Document docB = new Document(dataDir + "TestFile - Copy.doc");
// DocA now contains changes as revisions.
docA.Compare(docB, "user", DateTime.Now);
if (docA.Revisions.Count == 0)
Console.WriteLine("Documents are equal");
else
Console.WriteLine("Documents are not equal");
// ExEnd:CompareForEqual
}
示例4: Execute
protected override void Execute(CodeActivityContext executionContext)
{
// Get Values from the Input Parameters
bool Logging = EnableLogging.Get(executionContext);
string LicenseFilePath = LicenseFile.Get(executionContext);
string LogFilePath = LogFile.Get(executionContext);
int detectIn = DetectIn.Get(executionContext);
OutputAttachmentId.Set(executionContext, new EntityReference("annotation", Guid.Empty));
if (Logging)
Log("Execution Started", LogFilePath);
// Creating CRM service from Context
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
// Applying Licence for Aspose (If Exist)
if (Logging)
Log("Enable Licensing", LogFilePath);
if (LicenseFilePath != "" && File.Exists(LicenseFilePath))
{
License Lic = new License();
Lic.SetLicense(LicenseFilePath);
if (Logging)
Log("License Set", LogFilePath);
}
}
catch (Exception ex)
{
Log("Error while applying license: " + ex.Message, LogFilePath);
}
if (detectIn == 0) // under this record
{
Guid ThisRecordId = context.PrimaryEntityId;
string RecordType = context.PrimaryEntityName;
Document Result = new Document();
DocumentBuilder ResultWriter = new DocumentBuilder(Result);
if (Logging)
Log("Working under all attachments under this record", LogFilePath);
// Retrieve All attachments under this Record
QueryExpression RetrieveNoteQuery = new QueryExpression("annotation");
RetrieveNoteQuery.ColumnSet = new ColumnSet(new string[] { "filename", "subject", "documentbody" });
RetrieveNoteQuery.Criteria.AddCondition(new ConditionExpression("objectid", ConditionOperator.Equal, ThisRecordId));
if (Logging)
Log("Executing Query to retrieve All Notes within this record", LogFilePath);
EntityCollection Notes = service.RetrieveMultiple(RetrieveNoteQuery);
// Loop through All Notes
foreach (Entity Note in Notes.Entities)
{
try
{
if (Note.Contains("documentbody"))
{
string FileName = "";
if (Note.Contains("filename"))
FileName = Note["filename"].ToString();
// Read Attachment in Aspose
byte[] DocumentBody = Convert.FromBase64String(Note["documentbody"].ToString());
MemoryStream fileStream = new MemoryStream(DocumentBody);
Document doc = new Document(fileStream);
ResultWriter.Writeln("Comparing Document: " + FileName);
ResultWriter.StartTable();
// Comparing document with other attachments
foreach (Entity OtherNote in Notes.Entities)
{
if (OtherNote.Id != Note.Id)
{
if (OtherNote.Contains("documentbody"))
{
string OtherFileName = "";
if (OtherNote.Contains("filename"))
OtherFileName = OtherNote["filename"].ToString();
// Reading attachment in Aspose
byte[] OtherDocumentBody = Convert.FromBase64String(OtherNote["documentbody"].ToString());
MemoryStream fileStream2 = new MemoryStream(OtherDocumentBody);
Document doc2 = new Document(fileStream);
ResultWriter.InsertCell();
ResultWriter.Write(OtherFileName);
// Compare documents
doc.Compare(doc2, "a", DateTime.Now);
if (doc.Revisions.Count == 0)
{
// If documents are same
ResultWriter.InsertCell();
ResultWriter.Write("Duplicate Documents");
}
ResultWriter.EndRow();
}
}
}
ResultWriter.EndTable();
//.........这里部分代码省略.........
示例5: CompareDocumentWithRevisions
public void CompareDocumentWithRevisions()
{
Document doc1 = new Document(MyDir + "Document.Compare.1.doc");
Document docWithRevision = new Document(MyDir + "Document.Compare.Revisions.doc");
if (docWithRevision.Revisions.Count > 0)
Assert.That(() => docWithRevision.Compare(doc1, "authorName", DateTime.Now),
Throws.TypeOf<InvalidOperationException>());
}
示例6: CompareEx
public void CompareEx()
{
//ExStart
//ExFor:Document.Compare
//ExSummary:Shows how to apply the compare method to two documents and then use the results.
Document doc1 = new Document(MyDir + "Document.Compare.1.doc");
Document doc2 = new Document(MyDir + "Document.Compare.2.doc");
// If either document has a revision, an exception will be thrown.
if (doc1.Revisions.Count == 0 && doc2.Revisions.Count == 0)
doc1.Compare(doc2, "authorName", DateTime.Now);
// If doc1 and doc2 are different, doc1 now has some revisons after the comparison, which can now be viewed and processed.
foreach (Revision r in doc1.Revisions)
Console.WriteLine(r.RevisionType);
// All the revisions in doc1 are differences between doc1 and doc2, so accepting them on doc1 transforms doc1 into doc2.
doc1.Revisions.AcceptAll();
// doc1, when saved, now resembles doc2.
doc1.Save(MyDir + @"\Artifacts\Document.CompareEx.doc");
//ExEnd
}