python-docx and custom bullet style

Viewed 201

I have a very specific thing I'm trying to do, so I don't know if any of you could give me a tips on this.

The main thing I want to do is generating docx files from txt files.

I want this docx file to follow clear formatting rules, especially concerning bullet lists. I don't like the default Word listing styles, so I would have wanted to create my own one.

Sadly, I don't find in python-docx API anything concerning this issue : there is stuff for formatting paragraph, but it seems limited to indent, while I need to define the bullet I want to use.

Back in the days, my txt files were converted in old MS RTF format (with all the appropriate tags), so I also could try to use the RTF strings directly in the generated doc (I tried that with docxtpl), but I can't succeed on this.

Someone has an idea on this? I have found similar question but sadly there were no response, so I fear there is no solution.

1 Answers

Whatever .docx file you start with using document = Document("my_docx.docx") is the "template" file and whatever styles and other default settings it contains apply to the document you then generate using subsequent python-docx calls.

So if you don't like the default styles, just create a new empty document with Word and use the Word UI to edit those styles to suit, then save it and use that as your starting document. Then you can use the regular style names to get the customized result.

Related