4

If you see example here: https://www.geeksforgeeks.org/working-with-lists-python-docx-module/

Code is this:

# Import docx NOT python-docx
import docx

# Create an instance of a word document
doc = docx.Document()

# Add a Title to the document
doc.add_heading('GeeksForGeeks', 0)

# Adding list of style name 'List Number'
doc.add_heading('Style: List Number', 3)
# Adding points to the list named 'List Number'
doc.add_paragraph('The first item in an ordered list.',
                style='List Number')

doc.add_paragraph('The second item in an ordered list.',
                style='List Number')

doc.add_paragraph('The third item in an ordered list.',
                style='List Number')

# Adding list of style name 'List Number 2'
doc.add_heading('Style: List Number 2', 3)
# Adding points to the list named 'List Number 2'
doc.add_paragraph('The first item in an ordered list.',
                style='List Number 2')

doc.add_paragraph('The second item in an ordered list.',
                style='List Number 2')

doc.add_paragraph('The third item in an ordered list.',
                style='List Number 2')

# Adding list of style name 'List Number 3'
doc.add_heading('Style: List Number 3', 3)
# Adding points to the list named 'List Number 3'
doc.add_paragraph('The first item in an ordered list.',
                style='List Number 3')

doc.add_paragraph('The second item in an ordered list.',
                style='List Number 3')

doc.add_paragraph('The third item in an ordered list.',
                style='List Number 3')

# Now save the document to a location
doc.save('gfg.docx')

If for instance I change it List number 2 to just List number, number goes sequentially rather than starting over like this: output

How do I change it such that it is number for list 2 starts over from 1 - 3

template
  • 65
  • 4

1 Answers1

0

This solution here is what worked for me: https://stackoverflow.com/a/53574265/8754028

To summarize:

RRR
  • 513
  • 2
  • 6
  • 14