You can walk through the elements of the document

List<DocumentFormat.OpenXml.OpenXmlElement> elements = docx.MainDocumentPart.Document.Body.ToList(); 

OR

 List<DocumentFormat.OpenXml.OpenXmlElement> elements = docx.MainDocumentPart.Document.ToList(); 

But there is no background color of the document itself.

 foreach (DocumentFormat.OpenXml.OpenXmlElement element in elements) { List<RunProperties> runProps = element.Descendants<RunProperties>().ToList(); foreach (RunProperties rp in runProps) { rp.Color; } } 
  • Are you pulling it from an xml file? can xml also show? Be sure to use DocumentFormat.OpenXml - Vitaly Shebanits
  • Example xml -> xopusfiddle.net/2ffnU No, using DocumentFormat.OpenXml is optional, but how else can you work with OpenXml? - LocalUser 4:02 pm
  • Does this method suit you? - Vitaliy Shebanits 4:08 pm
  • I do not understand how to find out the background color of the document. You can try to use System.Xml, but how does this help to know the background color? - LocalUser
  • I suspect he's in style there. - Qwertiy

1 answer 1

If you mean the color that is set in Page Layout of the Page Background page color , then it lies in file.docx/word/document.xml in the color attribute of the background tag, in the root document tag and I managed to get it with the following code:

 using (var file = WordprocessingDocument.Open(filepath, isEditable: false)) { foreach (var db in file.MainDocumentPart.Document.ChildElements.OfType<DocumentBackground>()) Console.WriteLine(db.Color); } 

But keep in mind that it may not be there (in your document I don’t see it).

  • the problem is that I also don’t see the color and don’t understand what needs to be done to see it and pull it out - LocalUser
  • Throw off the document, we'll see - Andrew NOP
  • seems to have figured it out, thanks for the help - LocalUser
  • Tell me? .... - Andrew NOP