I ran
Python Version: 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)]
Pandas Version: 0.18.1
IPython Version: 4.2.0
and installed python-docx with
conda install -c conda-forge python-docx=0.8.6
I have a docx file with some tables in it and I would like either to
1) Copy some tables from the document to a new one, or
2) Remove some tables from the document,
lets say the first table, for 1) or 2).
For 1) I tried using this post here ( Python: Copy content from one word document to another word document and keeping format? ) but I get an
name 'opendocx' is not defined
error on the line
document = opendocx('xxxzzz.docx')
and if I replace opendocx with Document I get an
'Document' object has no attribute 'xpath'
error.
I guess opendocx is used on an earlier version or something, so I cannot solve the issue.
Any suggestions?
That post refers to a prior version of python-docx
, before it was rewritten to be object-oriented.
The documentation for python-docx
is here:
http://python-docx.readthedocs.org/en/latest/
You can't delete tables (yet), and you can't copy a whole object like a table either, so you would want to read the table from one document and reproduce it in the other, starting with document.add_table()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.