Search code examples
python-docx

with python-docx is there a way to set the Theme that is used for the document


When I create a new document it starts with the them "Basic (Simple)" is there a way to specify the them like "Black & White (Classic)"


Solution

  • Just use Word to create an empty document using the theme you want (along with any other customizations like specific styles and so forth) and use that as the starting point when you open a document with python-docx:

    document = Document("my-black-and-white-template.docx")
    

    All python-docx is doing when you don't specify a document to open is using an internal default document, which is the Basic (Simple) theme you mention; it is whatever was the default style for a new document in a fresh Word installation at the time that part of the python-docx library was written. It's that way for convenience in getting started and when you don't really care too much about the theme.