← 输入框|github.com|刷新
Skip to content

Default template creates documents in Word 2010 compatibility mode ( compatibilityMode=14 ). Propose updating to 15. #1634

Open

Description

@DjoleRkc

Documents created with  Document()  (no argument) open in Word with a "Compatibility Mode" banner. The built-in template sets  compatibilityMode  to  14  (Word 2010) instead of  15 , the value used by Word 2013 and later, including current Microsoft 365.

Since AI assistants such as GitHub Copilot started using python-docx, it has become one of the most common ways  .docx  files get created. Most of these flows call  Document()  without supplying their own starting file. We're seeing a large spike in new  .docx  files that open in compatibility mode, which:

• shows users a confusing "Compatibility Mode" banner on brand-new documents,
• turns off newer Word features until the user converts the document,
• and makes the documents lay out with legacy rules instead of current Word behaviour.

The workaround in #1543 (pass your own blank file to  Document() ) works, but in practice generated code almost never does this. The default is what most new documents get.

 compatibilityMode  is set in two bundled files:
•  src/docx/templates/default.docx , in  word/settings.xml 
•  src/docx/templates/default-settings.xml , the fallback when a package has no settings part

<w:compatSetting w:name="compatibilityMode" w:uri="http://schemas.microsoft.com/office/word" w:val="14"/>

Proposed fix

Change  w:val="14"  to  w:val="15"  in both files so  Document()  and the settings fallback stay consistent. No Python code changes are needed.

Changing the compatibility mode can, in theory, slightly change layout for a small number of documents that depend on Word 2010-era layout rules. We think the risk is acceptable, as we have not observed any layout changes when changing compatibility mode to 15 on our own dataset:

• it only affects newly created documents; existing documents opened with  Document(path)  keep their own settings,
• the legacy compatibility options tied to mode 14 are expected to be deprecated in Word in the coming months, so documents created in mode 14 will lose that legacy behaviour soon anyway,
•  15  is what current Word writes for every new document, so this only brings python-docx in line with the application.

I'm happy to open a PR with this change (both template files, plus any test updates). Please let me know if you'd prefer this approach, or regenerating  default.docx  from current Word (which would also refresh styles and theme, but makes a larger diff).

Posting on behalf of word native team 😄

Related: #1543

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions