Sathya

Sathya

  • NA
  • 96
  • 3k

how to get Styles from existing word document by using Docx

Mar 3 2017 7:17 AM
This is the code for OpenXML
 
 
  1. void AddStylesPart()  
  2. {  
  3. StyleDefinitionsPart styleDefinitionsPart = mainPart.StyleDefinitionsPart;  
  4. styleDefinitionsPart = mainPart.AddNewPart<StyleDefinitionsPart>();  
  5. Styles styles1 = new Styles();  
  6. styles1.Save(styleDefinitionsPart);  
  7. if (styleDefinitionsPart != null)  
  8. {  
  9. using (WordprocessingDocument wordTemplate = WordprocessingDocument.Open(@"..\AT\Docs\F4DEV.docx"false))  
  10. {  
  11. foreach (var templateStyle in wordTemplate.MainDocumentPart.StyleDefinitionsPart.Styles)  
  12. {  
  13. styleDefinitionsPart.Styles.Append(templateStyle.CloneNode(true));  
  14. }  
  15. }  
  16. }  
  17. }  
 
 
Here an existing document is taken using WordprocessingDocument class finally Cloned all the styles present in existing document, similarly I want to do it using Docx DLL. How to get styles used in existing document using Docx DLL? kindly please help. 
 
 
scenario: I have a word Document called Dev, they used different styles in it. I'm going to generate new word document, where I need to add styles which are present in Dev . These must be done using Docx dll