.net - Detecting bold, underline text and headings in word document with openxml sdk in c# -


i detect different styles , heading in selected word document openxml sdk in c#. have:

 public string getworddescription(string path)         {             string text = "";             system.io.packaging.package wordpackage = package.open(path, filemode.open, fileaccess.read);             using (wordprocessingdocument worddocument = wordprocessingdocument.open(wordpackage))             {                               body body = worddocument.maindocumentpart.document.body;                 if (body != null)                 {                     foreach (paragraph par in body.descendants<paragraph>())                     {                                                                       text += par.innertext;                         text += "<br />";                                                                   }                 }             }             return text;         } 

so while looping paragraphs somehow detect if there styling applied or if paragraph heading.

remember paragraphs blocks , blocks made of runs. in foreach loops you'll need inner loop loop through runs. run elements container runproperty elements describe inline formatting. or believe can use 1 loops following

foreach (run run in body.descendants<run>()) {    runproperties props = run.descendants<runproperties>();    if(props.descendants<bold>().first() != null)     {       //then    }     text += run.text;    text += "<br />";                                               } 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -