Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Feb 20, 2019 10:14 am

Hi,

I have 2 scenario:

1. Let say I were to extract a list of comments from a word document, how do I later on refer back the comment are from which paragraph? Is there any properties from the comment or paragraph?

2. I converted the word to html and then added some comments, how do I later on refer back the comment are from which paragraph in the word document?

vernon1111
 
Posts: 44
Joined: Fri Mar 02, 2018 4:34 am

Thu Feb 21, 2019 8:25 am

Hello,

Thanks for your post and below are my answers to your questions.
1. Please refer to below sample code to achieve your demand.
Code: Select all
 //Load Document
 Document doc = new Document();
 doc.LoadFromFile(@"sample.docx");
 //comments list
 List<string> list = new List<string>();
 list.Add("Test one.");
 list.Add("Test two.");
 StringBuilder SB = new StringBuilder();
 //comments of doc
 CommentsCollection commentC = doc.Comments;
 foreach (Comment comment in commentC)
 {
     Paragraph para = comment.OwnerParagraph;
     Section sec = comment.OwnerParagraph.Owner.Owner as Section;
     ParagraphCollection paraC = comment.Body.Paragraphs;
     for (int i = 0; i < list.Count; i++)
     {
         string listComment = list[i].ToString();
         foreach (Paragraph cpara in paraC)
         {
             if (listComment == cpara.Text)
             {
                 //index of comments section   
                 int secIndex = doc.Sections.IndexOf(sec);
                 //index of comments paragraph
                 int parIndex = sec.Body.Paragraphs.IndexOf(para);
                 String text = string.Format("The comment of list item {0} is in the paragraph {1} of section {2}", i + 1, parIndex + 1, secIndex + 1);
                 SB.AppendLine(text);
             }
         }
     }
 }
 File.WriteAllText("paragraphInformation.txt", SB.ToString());

2. To help us look into the issue accurately, please provide your original Word document and the HTML that you added some comments. You could send them to us via email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Tue Feb 26, 2019 6:21 am

Hello,

Greetings from E-iceblue.
Did my code help for your scenario 1? And as for your scenario 2, please provide the files that mentioned in previous reply to help us further look into it. Thanks in advance.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Fri Mar 01, 2019 10:42 am

Hi Lisa,

Thanks for the answer,

I will let you know again if I have more questions. :D

Thanks

vernon1111
 
Posts: 44
Joined: Fri Mar 02, 2018 4:34 am

Fri Mar 01, 2019 10:50 am

Hello,

Thanks for your feedback.
Just feel free to contact us if you need other helps. Have a nice day.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc