4

I'm running a code here:

import docx, os
os.chdir('C:\\PythonScripts')
doc = docx.Document()
doc.add_paragraph('Hello World!')
doc.paragraphs[0].style = 'Heading6'
doc.save('test.docx')

and I get that warning in the title. The script still works, but I think I'm doing something outdated in the newest updates. How do I do this correctly?

Steve Hemmingsen
  • 383
  • 5
  • 19
  • Possible duplicate of [python-docx style\_id error while creating a word document](https://stackoverflow.com/questions/28973277/python-docx-style-id-error-while-creating-a-word-document) – Al Sweigart May 24 '19 at 13:10

1 Answers1

6

You may change your

doc.paragraphs[0].style = 'Heading6'

to

doc.paragraphs[0].style = 'Heading 6'

and it shall work just fine.

HiRob
  • 420
  • 3
  • 10