Python CoreProperties python-docx

问题描述 投票:1回答:1

我需要了解docx的核心属性,包括作者,语言,创建的(日期),标识符,last_printed,修改的(日期),版本,标题,主题。我写了这段代码:

import docx
import os

os.chdir('C:\\abc\\Documents')
doc = docx.Document('ATD.docx')

docx.opc.coreprops.CoreProperties.author(doc)

我收到此错误:

TypeError:“属性”对象不可调用

如何从python代码中获取所需的信息?

python-3.x docx
1个回答
0
投票

我正在使用python-docx 0.8.10,不确定当时是否支持core properties,但现在事情应该很简单:

print(doc.core_properties.author)
>> 'name of the author'

为了列出所有可用的属性,请执行以下操作:

print(doc.core_properties.__dir__())

请注意,您还可以为identifierauthor等属性设置新值。>

doc.core_properties.author = '#stayathome!' # aren't we all enjoying covid-19
print(doc.core_properties.author)
>> '#stayathome!'

希望这会有所帮助,

最佳

© www.soinside.com 2019 - 2024. All rights reserved.