We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Have problem in getting the Font format of run when comparing 2 file words

I have problem in comparing 2 word file in case bold the word "Architect:"
When debugging I am able to get the object run however it can't get the format of run in case of Bold.
isBold always returns false
NodeCollection runs = para.GetChildNodes(NodeType.Run, false);
foreach (Run run in runs)
{
if (run.IsFormatRevision)
{
Run run = new Run(doc);
Aspose.Words.Font font = run.Font;
bool isBold = font.Bold;
}
}

Hi Minh,


Thanks for your inquiry. To compare two word files, we suggest you to use the Document.Compare method. It compares one document with another document producing changes as number of edit and format revisions Revision( tracked change in a document node or style). Please Use latest version of Aspose.Words for .NET and try following code. Hope this helps you.


Document doc1 = new Document(MyDir + @"Original+Doc.docx");

Document doc2 = new Document(MyDir + @"Formatted+Doc.docx");

doc2.Compare(doc1, "ah", DateTime.Now);

NodeCollection runs = doc2.GetChildNodes(NodeType.Run, true);

foreach (Run run in runs)

{

if (run.IsFormatRevision)

{

Aspose.Words.Font font = run.Font;

bool isBold = font.Bold;

Console.WriteLine(run.Text + " --> " + isBold);

}

}


For more information, please visit How to Compare Two Word Documents. If you still face problem, please create stand-alone application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing. We will then provide you more information on this.

I have already use this in my code. After comparing, I have already have all Revisions which lets me know the doc include RevisionType Format change. However, we can’t get which format is applied to the revision including Bold, Italic, Underline, Strikethrough

Hi Minh,


Thanks for your inquiry. Please use latest version of Aspose.Words for .NET and try following code. Hope this helps you.


foreach (Revision rev in doc2.Revisions)

{

if (rev.ParentNode.NodeType.Equals(NodeType.Run))

{

Run run = rev.ParentNode as Run;

Console.WriteLine("run.Font.Bold --> " + run.Font.Bold);

Console.WriteLine("Font.Italic --> " + run.Font.Italic);

Console.WriteLine("Font.Bold --> " + run.Font.Bold);

Console.WriteLine("Font.Underline --> " + run.Font.Underline);

Console.WriteLine("Font.StrikeThrough --> " + run.Font.StrikeThrough);

}

}


If you still face any problem, please let us know we will try to help you as much we can. Thanks.

Thank for your replying. I have already tried your code. Unfortunately the issue isn't able to be resolved.
When debugging, I realize that its return me the doc1 object which isn't applied the format change.
It can get which revision.RevisionType is equal to RevisionType.FormatChange. Howerver we can't get the format change of the run according to the revision as your code
Run run = rev.ParentNode as Run;
Console.WriteLine("run.Font.Bold --> " + run.Font.Bold);
Console.WriteLine("Font.Italic --> " + run.Font.Italic);
Console.WriteLine("Font.Bold --> " + run.Font.Bold);
Console.WriteLine("Font.Underline --> " + run.Font.Underline);
Console.WriteLine("Font.StrikeThrough --> " + run.Font.StrikeThrough);

Here is my code example:
// Load both documents in Aspose.Words
Document doc1 = new Document(document1);
Document doc2 = new Document(document2);
doc1.Compare(doc2, "a", DateTime.Now);
try
{
foreach (Revision rev in doc1.Revisions)
{
if (rev.ParentNode.NodeType.Equals(NodeType.Run))
{
Run run = rev.ParentNode as Run;
Console.WriteLine("run.Font.Bold --> " + run.Font.Bold);
Console.WriteLine("Font.Italic --> " + run.Font.Italic);
Console.WriteLine("Font.Bold --> " + run.Font.Bold);
Console.WriteLine("Font.Underline --> " + run.Font.Underline);
Console.WriteLine("Font.StrikeThrough --> " + run.Font.StrikeThrough);
}
}
}
catch(Exception ex)
{
string str = ex.Message;
}

Hi Minh,


Thanks for sharing the detail. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-14681. You will be notified via this forum thread once this issue is resolved.


We apologize for your inconvenience.

I have problem in comparing 2 word file in case bold the word "Architect:"
When debugging I am able to get the object run however it can't get the format of run in case of Bold.
isBold always returns false
It can get which revision.RevisionType is equal to RevisionType.FormatChange. Howerver we can't get the format change of the run according to the revision as your code
Run run = rev.ParentNode as Run;
Console.WriteLine("run.Font.Bold --> " + run.Font.Bold);
Console.WriteLine("Font.Italic --> " + run.Font.Italic);
Console.WriteLine("Font.Bold --> " + run.Font.Bold);
Console.WriteLine("Font.Underline --> " + run.Font.Underline);
Console.WriteLine("Font.StrikeThrough --> " + run.Font.StrikeThrough);
Here is my code demo:
// Load both documents in Aspose.Words
Document doc1 = new Document(document1);
Document doc2 = new Document(document2);
doc1.Compare(doc2, "a", DateTime.Now);
try
{
foreach (Revision rev in doc1.Revisions)
{
if (rev.ParentNode.NodeType.Equals(NodeType.Run))
{
Run run = rev.ParentNode as Run;
Console.WriteLine("run.Font.Bold --> " + run.Font.Bold);
Console.WriteLine("Font.Italic --> " + run.Font.Italic);
Console.WriteLine("Font.Bold --> " + run.Font.Bold);
Console.WriteLine("Font.Underline --> " + run.Font.Underline);
Console.WriteLine("Font.StrikeThrough --> " + run.Font.StrikeThrough);
}
}
}
catch(Exception ex)
{
string str = ex.Message;
}