daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. _p = self._str_i.add_paragraph("Table of Contents")
  2. paragraph = self._str_i.add_paragraph()
  3. run = paragraph.add_run()
  4. fldChar = OxmlElement('w:fldChar')  # creates a new element
  5. fldChar.set(qn('w:fldCharType'), 'begin')  # sets attribute on element
  6. instrText = OxmlElement('w:instrText')
  7. instrText.set(qn('xml:space'), 'preserve')  # sets attribute on element
  8. instrText.text = 'TOC \\o "1-5" \\h \\z \\u'   # change 1-5 depending on heading levels you need
  9. fldChar2 = OxmlElement('w:fldChar')
  10. fldChar2.set(qn('w:fldCharType'), 'separate')
  11. fldChar3 = OxmlElement('w:t')
  12. fldChar3.text = "Right-click to update table of contents!!."
  13. fldChar2.append(fldChar3)
  14. fldChar4 = OxmlElement('w:fldChar')
  15. fldChar4.set(qn('w:fldCharType'), 'end')
  16. r_element = run._r
  17. r_element.append(fldChar)
  18. r_element.append(instrText)
  19. r_element.append(fldChar2)
  20. r_element.append(fldChar4)
  21. p_element = paragraph._p
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top