はじめに
Python-docxを数時間前に使い始めました。
環境
Pyhthon3(Python 3.6.4)
MacOS High Sierra 10.13.3
やりたいこと
Python-docxを使い、既存のdocxファイルを編集したい。
その際、文章にコメントと変更履歴を追加したい。
やったこと
以下のようなコードを書きました。
python
1# -*- coding: utf-8 -*- 2 3from docx import Document 4 5# 既存ファイルの読み出し 6document = Document('base.docx') 7 8cnt = 0 9for value in document.paragraphs: 10 # もし文章中に「hoge」があれば 11 if (value.text.find('fuge') > -1): 12 # 置換 13 document.paragraphs[cnt].text = value.text.replace('hoge', 'fuge') 14 # コメントとか追加? 15 document.core_properties.author = 'Nな人' 16 document.core_properties.revision = cnt + 1 17 document.core_properties.comments_text = str(cnt + 1) + '番目のコメントだぞ' 18 19 print(document.paragraphs[cnt]) 20 21 cnt = cnt + 1 22 23for value in document.paragraphs: 24 pass 25 # print(value.text) 26 27# 保存 28document.save('python_out.docx')
しかし、文章の置換は書き出せましたが、
コメントや校閲(revision?)は反映されませんでした……
これはなぜなのでしょうか?
ご存じの方がいらっしゃいましたら、ご教示いただけますと幸いです。
よろしくお願いいたします。
あなたの回答
tips
プレビュー