2017-04-25 89 views
0

我跑表格複製到另一個

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 

和安裝蟒蛇,DOCX與

conda install -c conda-forge python-docx=0.8.6 

我有它的一些表一的docx文件,我想要麼

1)將文檔中的一些表格複製到新的表格中,或者

2)刪除一些表格es從文件中,

可以說第一個表格,用於1)或2)。

對於1)我試圖用這個帖子在這裏(Python: Copy content from one word document to another word document and keeping format?) ,但我上線的

name 'opendocx' is not defined 

錯誤

document = opendocx('xxxzzz.docx') 

,如果我更換 opendocx 與 文件 我得到一個

'Document' object has no attribute 'xpath' 

錯誤。

我猜opendocx是在早期版本或其他東西上使用的,所以我無法解決問題。

有什麼建議嗎?

回答

0

該帖子指的是之前版本的python-docx,在它被重寫爲面向對象之前。

python-docx的文檔是在這裏:
http://python-docx.readthedocs.org/en/latest/

不能刪除表(還),你不能複製整個物體,像表可能,所以你會想讀表從一個文件並在另一個文件中重現,從document.add_table()開始。

+0

感謝您的回答。我知道文檔,但我想複製表格,以便保留所有內容和格式,樣式,行列尺寸等。關於如何做到這一點的任何建議? – akotronis

相關問題