Python 核心属性 python-docx
Python CoreProperties python-docx
我需要知道 docx 的核心属性,如作者、语言、创建(日期)、标识符、last_printed、修改(日期)、版本、标题、主题。我写了这段代码:
import docx
import os
os.chdir('C:\abc\Documents')
doc = docx.Document('ATD.docx')
docx.opc.coreprops.CoreProperties.author(doc)
我收到这个错误:
TypeError: 'property' object is not callable
如何从 python 代码中获取我需要的信息?
我正在使用 python-docx 0.8.10
,不确定当时是否支持 core properties,但现在应该很简单了:
print(doc.core_properties.author)
>> 'name of the author'
为了列出所有可用属性,请执行以下操作:
print(doc.core_properties.__dir__())
请注意,您还可以为 identifier
、author
等属性设置新值。
doc.core_properties.author = '#stayathome!' # aren't we all enjoying covid-19
print(doc.core_properties.author)
>> '#stayathome!'
希望这对您有所帮助,
最佳
我需要知道 docx 的核心属性,如作者、语言、创建(日期)、标识符、last_printed、修改(日期)、版本、标题、主题。我写了这段代码:
import docx
import os
os.chdir('C:\abc\Documents')
doc = docx.Document('ATD.docx')
docx.opc.coreprops.CoreProperties.author(doc)
我收到这个错误:
TypeError: 'property' object is not callable
如何从 python 代码中获取我需要的信息?
我正在使用 python-docx 0.8.10
,不确定当时是否支持 core properties,但现在应该很简单了:
print(doc.core_properties.author)
>> 'name of the author'
为了列出所有可用属性,请执行以下操作:
print(doc.core_properties.__dir__())
请注意,您还可以为 identifier
、author
等属性设置新值。
doc.core_properties.author = '#stayathome!' # aren't we all enjoying covid-19
print(doc.core_properties.author)
>> '#stayathome!'
希望这对您有所帮助,
最佳