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

Free Support Forum - aspose.com

Reading comments from the word document

hi ,
I have a need to read a paragraph of the document which has comments associated with it and copy that to a new word doc ( including the comments) .
I do not see a way to read the comments from the old doc,
Please help advice how can i proceed with this need

Hi

Thanks for your request. You can try using the following code to achieve what you need.

// Open input document.

Document doc = new Document("C:\\Temp\\in.doc");

// Create a document where we will copy paragraphs with comments.

Document dst = new Document();

// Create an importer that will allow us to copy nodes from source document to destination.

NodeImporter importer = new NodeImporter(doc, dst, ImportFormatMode.KEEP_SOURCE_FORMATTING);

// Get all comments from the source document.

Node[] comments = doc.getChildNodes(NodeType.COMMENT, true).toArray();

// Loop through all comments and copy paragraph that contains these comments to the dst doc.

for(Node commentNode : comments)

{

// Get parent paragraph and copy it to the dst doc.

Node dstNode = importer.importNode(commentNode.getAncestor(NodeType.PARAGRAPH), true);

// Insert imported node to the destination document.

dst.getFirstSection().getBody().appendChild(dstNode);

}

// Save output document.

dst.save("C:\\Temp\\out.doc");

Hope this helps.

Best regards,

Thanks for the response,

how to read the track changes comments ( the bubble which gets added in the right hand side stating what was deleted/inserted etc from the word doc). the previous comment object lookup does not give hold of it.
Is there any way to read the track changes comments programatically through aspose?

Hi

Thanks for your request. At the moment you can only read insert and delete revisions using Aspose.Words. unfortunately, there is no way to programmatically access formatting revisions.

Regarding insert/delete revisions, Paragraph and Run nodes has properties named IsInsertRevision and IsDeleteRevision . These properties indicated whether the corresponding node is insert or delete revision.

Best regards,

ok thanks
how about i need to read the texts which was deleted and that shows up in the bubble in the right hand side saying what was deleted
e.g attached the image of deleted bubble which microsoft word shows , so in this case i want to read the text " Best Buy Co., Inc."

Hello,

Thank you for your inquiry.
Try using this code here.

class Program<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

{

static void Main()

{

License lic = new License();

lic.SetLicense("Aspose.Words.lic");

Document doc = new Document("X:\\test.docx");

RunVisitor visitor = new RunVisitor();

doc.Accept(visitor);

Console.Read();

}

}

public class RunVisitor : DocumentVisitor

{

///

/// Called when a Run node is encountered in the document.

///

public override VisitorAction VisitRun(Run run)

{

if(run.IsDeleteRevision)

{

Console.WriteLine(string.Format("This is deleted text = {0}", run.Text));

}

if(run.IsInsertRevision)

{

Console.WriteLine(string.Format("This is inserted text = {0}", run.Text));

}

// Let the visitor continue visiting other nodes.

return VisitorAction.Continue;

}

}

If you have any other problems, please feel free to ask.

The issues you have found earlier (filed as WORDSNET-3330) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(13)