-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A follow up on the issue of Figure caption #359
Comments
Hello, I am relatively new to Python and python-docx. in Figure Can anyone clarify this issue for me? Thanks so much! |
@Anne1029384756 I believe if you add |
Thank you for your reply! I installed python-pptx using pip install. I import the element as described, but I still get an error. Any thoughts on this one? from pptx.oxml import OxmlElement |
Dear Anne and Steve,
Here is an example of the function that I am using that works pretty well. You can add figures, images in the figures
as well as Tables.
You just have to update the Figure and Table numbers in the word document.
Best, Daniel
On 27 Feb 2018, at 18:38, Steve Canny <[email protected]<mailto:[email protected]>> wrote:
@Anne1029384756<https://github.com/anne1029384756> I believe if you add from pptx.oxml import OxmlElement above your code that will do the trick.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#359 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AI7G1j1A_WAGC7BZlpPjprqlue3knkA2ks5tZD13gaJpZM4L1lh->.
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/python-openxml/python-docx","title":"python-openxml/python-docx","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/python-openxml/python-docx"}},"updates":{"snippets":[{"icon":"PERSON","message":"@scanny in #359: @Anne1029384756 I believe if you add `from pptx.oxml import OxmlElement` above your code that will do the trick."}],"action":{"name":"View Issue","url":"#359 (comment)"}}}
|
Sorry, no need to install |
@DBGVA: I am unable to find/see your example code. Where did you put it? @scanny: after succesfully importing the OxmlElement from docx.oxml, I now get a different error. I tried importing qn in a similar manner, but that is not possible. fldChar.set(qn('w:fldCharType'), 'begin') |
Hi the example as in the file Figures.Tables.py that I am attaching again
This should work smoothly.
On 28 Feb 2018, at 15:45, Anne1029384756 <[email protected]<mailto:[email protected]>> wrote:
@DBGVA<https://github.com/dbgva>: I am unable to find/see your example code. Where did you put it?
@scanny<https://github.com/scanny>: after succesfully importing the OxmlElement from docx.oxml, I now get a different error. I tried importing qn in a similar manner, but that is not possible.
fldChar.set(qn('w:fldCharType'), 'begin')
NameError: name 'qn' is not defined
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#359 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AI7G1s_VJ0EiKhQacbQySJunaR1k03vPks5tZWWegaJpZM4L1lh->.
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/python-openxml/python-docx","title":"python-openxml/python-docx","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/python-openxml/python-docx"}},"updates":{"snippets":[{"icon":"PERSON","message":"@Anne1029384756 in #359: @DBGVA: I am unable to find/see your example code. Where did you put it?\r\n\r\n@scanny: after succesfully importing the OxmlElement from docx.oxml, I now get a different error. I tried importing qn in a similar manner, but that is not possible.\r\n\r\nfldChar.set(qn('w:fldCharType'), 'begin')\r\nNameError: name 'qn' is not defined\r\n\r\n"}],"action":{"name":"View Issue","url":"#359 (comment)"}}}
|
I am so sorry! I still cannot find it. Not as a usual attachement to the
email and there is nothing special visible in the Github thread. But I am
new to the system so I might be looking in the wrong places. If it is a
short piece of code, perhaps you could copy it directly?
2018-02-28 15:49 GMT+01:00 DBGVA <[email protected]>:
… Hi the example as in the file Figures.Tables.py that I am attaching again
This should work smoothly.
On 28 Feb 2018, at 15:45, Anne1029384756 ***@***.***<mailto:
***@***.***>> wrote:
@DBGVA<https://github.com/dbgva>: I am unable to find/see your example
code. Where did you put it?
@scanny<https://github.com/scanny>: after succesfully importing the
OxmlElement from docx.oxml, I now get a different error. I tried importing
qn in a similar manner, but that is not possible.
fldChar.set(qn('w:fldCharType'), 'begin')
NameError: name 'qn' is not defined
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://github.com/
python-openxml/python-docx#359#issuecomment-369259942>, or mute
the thread<https://github.com/notifications/unsubscribe-auth/AI7G1s_
VJ0EiKhQacbQySJunaR1k03vPks5tZWWegaJpZM4L1lh->.
{"api_version":"1.0","publisher":{"api_key":"
05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":
{"external_key":"github/python-openxml/python-docx","
title":"python-openxml/python-docx","subtitle":"GitHub
repository","main_image_url":"https://cloud.githubusercontent.com/assets/
143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","
avatar_image_url":"https://cloud.githubusercontent.com/
assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png
","action":{"name":"Open in GitHub","url":"https://github.
com/python-openxml/python-docx"}},"updates":{"snippets":[{"
***@***.*** in #359: @DBGVA: I am unable to
find/see your example code. Where did you put ***@***.***: after
succesfully importing the OxmlElement from docx.oxml, I now get a different
error. I tried importing qn in a similar manner, but that is not
possible.\r\n\r\nfldChar.set(qn('w:fldCharType'), 'begin')\r\nNameError:
name 'qn' is not defined\r\n\r\n"}],"action":{"name":"View Issue","url":"
#359 (comment)-
369259942"}}}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#359 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AjLr82BjmMZpJ69KKgkZlWpuPunli9Xcks5tZWcLgaJpZM4L1lh->
.
|
Sorry, I had not realised that it was cut off. Here is the code
from xlrd import open_workbook,XL_CELL_TEXT,XLRDError
import xlsxwriter
from xlrd import open_workbook
import os,sys
import shutil
from docx import Document
from docx.shared import Cm
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
from xlrd import open_workbook,XL_CELL_TEXT,XLRDError
def MarkIndexEntry(entry,paragraph):
run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
run = paragraph.add_run()
r = run._r
instrText = OxmlElement('w:instrText')
instrText.set(qn('xml:space'), 'preserve')
instrText.text = ' XE "%s" '%(entry)
r.append(instrText)
run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar)
def Figure(paragraph):
run = run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
instrText = OxmlElement('w:instrText')
instrText.text = ' SEQ Figure \* ARABIC'
r.append(instrText)
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar)
def Table(paragraph):
run = run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
instrText = OxmlElement('w:instrText')
instrText.text = ' SEQ Table \* ARABIC'
r.append(instrText)
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar)
#
# The main program
#
document = Document()
paragraph = document.add_paragraph('')
paragraph = document.add_paragraph('Figure ', style='Caption')
Figure(paragraph)
paragraph.add_run(' Figure Caption ')
#document.add_picture(FileDir + FileName, width=Cm(10))
paragraph = document.add_paragraph('Figure Text', style='BodyText')
document.add_page_break()
document.save(str.strip('Test-Figures.docx'))
On 28 Feb 2018, at 16:12, Anne1029384756 <[email protected]<mailto:[email protected]>> wrote:
I am so sorry! I still cannot find it. Not as a usual attachement to the
email and there is nothing special visible in the Github thread. But I am
new to the system so I might be looking in the wrong places. If it is a
short piece of code, perhaps you could copy it directly?
2018-02-28 15:49 GMT+01:00 DBGVA <[email protected]<mailto:[email protected]>>:
Hi the example as in the file Figures.Tables.py that I am attaching again
This should work smoothly.
On 28 Feb 2018, at 15:45, Anne1029384756 ***@***.******@***.***><mailto:
***@***.******@***.***>>> wrote:
@DBGVA<https://github.com/dbgva>: I am unable to find/see your example
code. Where did you put it?
@scanny<https://github.com/scanny>: after succesfully importing the
OxmlElement from docx.oxml, I now get a different error. I tried importing
qn in a similar manner, but that is not possible.
fldChar.set(qn('w:fldCharType'), 'begin')
NameError: name 'qn' is not defined
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://github.com/
python-openxml/python-docx#359#issuecomment-369259942>, or mute
the thread<https://github.com/notifications/unsubscribe-auth/AI7G1s_
VJ0EiKhQacbQySJunaR1k03vPks5tZWWegaJpZM4L1lh->.
{"api_version":"1.0","publisher":{"api_key":"
05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":
{"external_key":"github/python-openxml/python-docx","
title":"python-openxml/python-docx","subtitle":"GitHub
repository","main_image_url":"https://cloud.githubusercontent.com/assets/
143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","
avatar_image_url":"https://cloud.githubusercontent.com/
assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png
","action":{"name":"Open in GitHub","url":"https://github.
com/python-openxml/python-docx"}},"updates":{"snippets":[{"
***@***.*** in #359: @DBGVA: I am unable to
find/see your example code. Where did you put ***@***.***: after
succesfully importing the OxmlElement from docx.oxml, I now get a different
error. I tried importing qn in a similar manner, but that is not
possible.\r\n\r\nfldChar.set(qn('w:fldCharType'), 'begin')\r\nNameError:
name 'qn' is not defined\r\n\r\n"}],"action":{"name":"View Issue","url":"
#359 (comment)-
369259942"}}}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#359 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AjLr82BjmMZpJ69KKgkZlWpuPunli9Xcks5tZWcLgaJpZM4L1lh->
.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#359 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AI7G1oduzpztyotyFHjSe3ki5kB1LCXfks5tZWzqgaJpZM4L1lh->.
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/python-openxml/python-docx","title":"python-openxml/python-docx","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/python-openxml/python-docx"}},"updates":{"snippets":[{"icon":"PERSON","message":"@Anne1029384756 in #359: I am so sorry! I still cannot find it. Not as a usual attachement to the\nemail and there is nothing special visible in the Github thread. But I am\nnew to the system so I might be looking in the wrong places. If it is a\nshort piece of code, perhaps you could copy it directly?\n\n2018-02-28 15:49 GMT+01:00 DBGVA \[email protected]<mailto:[email protected]>\u003e:\n\n\u003e Hi the example as in the file Figures.Tables.py that I am attaching again\n\u003e\n\u003e\n\u003e This should work smoothly.\n\u003e\n\u003e On 28 Feb 2018, at 15:45, Anne1029384756 \[email protected]<mailto:[email protected]>\u003cmailto:\n\u003e [email protected]<mailto:[email protected]>\u003e\u003e wrote:\n\u003e\n\u003e\n\u003e @DBGVA\u003chttps://github.com/dbgva\u003e: I am unable to find/see your example\n\u003e code. Where did you put it?\n\u003e\n\u003e @scanny\u003chttps://github.com/scanny\u003e: after succesfully importing the\n\u003e OxmlElement from docx.oxml, I now get a different error. I tried importing\n\u003e qn in a similar manner, but that is not possible.\n\u003e\n\u003e fldChar.set(qn('w:fldCharType'), 'begin')\n\u003e NameError: name 'qn' is not defined\n\u003e\n\u003e —\n\u003e You are receiving this because you were mentioned.\n\u003e Reply to this email directly, view it on GitHub\u003chttps://github.com/\n\u003e python-openxml/python-docx#359#issuecomment-369259942\u003e, or mute\n\u003e the thread\u003chttps://github.com/notifications/unsubscribe-auth/AI7G1s_\n\u003e VJ0EiKhQacbQySJunaR1k03vPks5tZWWegaJpZM4L1lh-\u003e.\n\u003e\n\u003e {\"api_version\":\"1.0\",\"publisher\":{\"api_key\":\"\n\u003e 05dde50f1d1a384dd78767c55493e4bb\",\"name\":\"GitHub\"},\"entity\":\n\u003e {\"external_key\":\"github/python-openxml/python-docx\",\"\n\u003e title\":\"python-openxml/python-docx\",\"subtitle\":\"GitHub\n\u003e repository\",\"main_image_url\":\"https://cloud.githubusercontent.com/assets/\n\u003e 143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png\",\"\n\u003e avatar_image_url\":\"https://cloud.githubusercontent.com/\n\u003e assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png\n\u003e \",\"action\":{\"name\":\"Open in GitHub\",\"url\":\"https://github.\n\u003e com/python-openxml/python-docx\"}},\"updates\":{\"snippets\":[{\"\n\u003e icon\":\"PERSON\",\"message\":\"@Anne1029384756 in #359: @DBGVA: I am unable to\n\u003e find/see your example code. Where did you put it?\\r\\n\\r\\n@scanny: after\n\u003e succesfully importing the OxmlElement from docx.oxml, I now get a different\n\u003e error. I tried importing qn in a similar manner, but that is not\n\u003e possible.\\r\\n\\r\\nfldChar.set(qn('w:fldCharType'), 'begin')\\r\\nNameError:\n\u003e name 'qn' is not defined\\r\\n\\r\\n\"}],\"action\":{\"name\":\"View Issue\",\"url\":\"\n\u003e #359 (comment)-\n\u003e 369259942\"}}}\n\u003e\n\u003e —\n\u003e You are receiving this because you were mentioned.\n\u003e Reply to this email directly, view it on GitHub\n\u003e \u003chttps://github.com/python-openxml/python-docx/issues/359#issuecomment-369261933\u003e,\n\u003e or mute the thread\n\u003e \u003chttps://github.com/notifications/unsubscribe-auth/AjLr82BjmMZpJ69KKgkZlWpuPunli9Xcks5tZWcLgaJpZM4L1lh-\u003e\n\u003e .\n\u003e\n"}],"action":{"name":"View Issue","url":"#359 (comment)"}}}
|
@DBGVA Thanks! I have both code versions working at the moment! @scanny Importing both of the following fixed the initial code: Next step for me is fixing references to specific figures/tables. (I am used to working with LateX). I will post my question in another feed, but if you also have a solution for that please let me know! |
With this code, the caption appears above the image. |
Change the order and add the picture before adding the caption part: document.add_picture() paragraph = document.add_paragraph('Figure ', style='Caption') |
Just a note for those who fell into the same trap: While trying to figure out why I was getting "bookmark not found" errors, I also discovered a kluge that works if you open the document into MS Word:
I'm sure this is a fully unsupported approach, though. |
You need write two backslash and not just one.
|
Dear all, 1) it is possible to restart figure numbering when new heading is added: document.add_heading('A heading', 0) 2) or its is possible to display figure numbering as below (even better): document.add_heading('A heading', 0) I am using the following Figure definition (as per above in the thread) Thanks a lot |
Is there a way tk completely disable numbering |
I did some refactoring and fixing on the code you all posted here. I'm not sure what happens here but it seems to work. You see the number is missing. Do mark the whole document (CMD+A) and then press F9 to update all fields. Then the number appears. I'm currently looking for a solution to let the numbering appear in the first place. Not sure how word does that. The codeThat code should work for tables. It is also prepared to work for figures, too. But I never used figures with docx so I don't know how to create them. There is also the
|
Please let ask an additional option including a possible solution. Please let me know if my approach make sense to you with your knowledge about the docx internals. I would like modify the position of a caption for a table/figure from bottom to top. Is it that easy to just create the caption paragraph before the table object? Or should we do some more "magic"? |
This is a feature request that has received a lot of interest, and a mostly-working example of how to accomplish this has been posted in the comments above. Is there a reason why this cannot be incorporated into the codebase? |
The project is in maintenance mode. This means no new features. The maintainer only does fix bugs or answer some questions from time to time. I am sure he will appreciate every help he can get. |
Huh. Well, if anybody wants to use caption numbering like def addCaption(doc, captionType, captionText):
"""
Use this to insert a caption with dynamic numbering into the document.
When you open the word doc, you must do ctrl+A -> F9 in order for the dynamic
numbers to actually appear. Numbering of tables and figures will be independent.
Parameters
----------
doc : docx.Document
captionType : str
The type of caption. Either "Figure" or "Table".
captionText : str
The description that is the bulk of the caption.
"""
paragraph = doc.add_paragraph(f"{captionType} ", style="Caption")
paragraph.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER
# add in the part of the numbering corresponding to the section
# i.e. X in Figure X-Y
run = paragraph.add_run()
fldChar = docx.oxml.OxmlElement("w:fldChar")
fldChar.set(docx.oxml.ns.qn("w:fldCharType"), "begin")
run._r.append(fldChar)
instrText = docx.oxml.OxmlElement("w:instrText")
instrText.text = fr" STYLEREF 1 \s "
run._r.append(instrText)
fldChar = docx.oxml.OxmlElement("w:fldChar")
fldChar.set(docx.oxml.ns.qn("w:fldCharType"), "end")
run._r.append(fldChar)
paragraph.add_run("-")
# add the part of the numbering corresponding to the index within the section
# i.e. Y in Figure X-Y
run = paragraph.add_run()
fldChar = docx.oxml.OxmlElement("w:fldChar")
fldChar.set(docx.oxml.ns.qn("w:fldCharType"), "begin")
run._r.append(fldChar)
instrText = docx.oxml.OxmlElement("w:instrText")
instrText.text = fr" SEQ {captionType} \* ARABIC \s 1 "
run._r.append(instrText)
fldChar = docx.oxml.OxmlElement("w:fldChar")
fldChar.set(docx.oxml.ns.qn("w:fldCharType"), "end")
run._r.append(fldChar)
paragraph.add_run(f": {captionText}") |
|
Hi @sailist , do you care to add some description of what your code does? |
Here is an example you can refer to: from docx import Document
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
def pre_ref(run, cross_refs: list):
for cref in cross_refs:
bookmarkStart = OxmlElement("w:bookmarkStart")
bookmarkStart.set(qn("w:id"), f"{cref['attrs']['w:id']}")
bookmarkStart.set(qn("w:name"), cref["attrs"]["w:name"])
run._r.append(bookmarkStart)
def post_ref(run, cross_refs: list):
for cref in cross_refs:
bookmarkEnd = OxmlElement("w:bookmarkEnd")
bookmarkEnd.set(qn("w:id"), f"{cref['attrs']['w:id']}")
run._r.append(bookmarkEnd)
def add_label(paragraph, label_type, refname: str, cross_refs: list, prefix=""):
paragraph.add_run("")
# numbering field
run = paragraph.add_run(" ")
pre_ref(run, cross_refs)
if len(prefix) > 0:
run.add_text(f"{prefix} ")
fldChar = OxmlElement("w:fldChar")
fldChar.set(qn("w:fldCharType"), "begin")
run._r.append(fldChar)
instrText = OxmlElement("w:instrText")
instrText.text = f" SEQ {label_type} \\* ARABIC"
run._r.append(instrText)
fldChar = OxmlElement("w:fldChar")
fldChar.set(qn("w:fldCharType"), "end")
run._r.append(fldChar)
run.add_text(". ")
post_ref(run, cross_refs)
def add_ref_place(paragraph, token):
# caption type
run = paragraph.add_run("")
fldChar = OxmlElement("w:fldChar")
fldChar.set(qn("w:fldCharType"), "begin")
run._r.append(fldChar)
ref_name = token["attrs"]["w:name"]
instrText = OxmlElement("w:instrText")
instrText.text = f" REF {ref_name} \\h"
run._r.append(instrText)
fldChar = OxmlElement("w:fldChar")
fldChar.set(qn("w:fldCharType"), "end")
run._r.append(fldChar)
doc = Document()
# pre analysys before generate docx to get all cross_refs
cross_refs = [{"attrs": {"w:id": "1", "w:name": "bookmark1"}}]
# that makes sure you can add reference before label position
paragraph = doc.add_paragraph()
add_ref_place(paragraph, cross_refs[0])
paragraph = doc.add_paragraph()
add_label(
paragraph, label_type="Figure", refname="fig1", cross_refs=cross_refs, prefix="Fig"
)
for i in range(10):
paragraph = doc.add_paragraph(f"i: {i}")
# add reference after label position
paragraph = doc.add_paragraph()
add_ref_place(paragraph, cross_refs[0])
doc.save("output.docx") |
Thanks to the latest developments presented in #137 it is now possible to insert an automatic figure or table caption using the following code.
def Figure(paragraph):
run = run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
instrText = OxmlElement('w:instrText')
instrText.text = ' SEQ Figure * ARABIC'
r.append(instrText)
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar)
def Table(paragraph):
run = run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
instrText = OxmlElement('w:instrText')
instrText.text = ' SEQ Table * ARABIC'
r.append(instrText)
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar)
-----------in the main document-------
paragraph = document.add_paragraph('Figure ', style='Caption')
Figure (paragraph)
--- while the figure or table number might not appear immediately they will show up after an update
moreover the code can be viewed using the "toggle field view"
Thanks to everybody
The text was updated successfully, but these errors were encountered: