我需要能够使用Python查看xlsx文件的"last modified by“属性。我已经能够处理docx文件,并希望该体系结构足够类似于其他Office应用程序,但不幸的是不能。有谁知道xlsx有类似的模块吗?
以下是使用python-docx查看字段的脚本:
from docx import Document
import docx
document = Document('mine.docx')
core_properties = document.core_properties
print(core_properties.last_modified_by)
我在这里使用的是Python 3.4和docx 0.8.6。
发布于 2016-11-08 17:50:01
对于.xlsx
文件,可以使用以下命令(将filename
设置为.xlsx
文件的名称):
import xml.etree.ElementTree
import xml.etree.cElementTree as ET
import zipfile
corePropNS = '{http://schemas.openxmlformats.org/package/2006/metadata/core-properties}'
zf = zipfile.ZipFile(filename, 'r')
part = zf.open('docProps/core.xml', 'r')
tree = ET.XML(part.read())
lastModifiedBy = tree.find(corePropNS+'lastModifiedBy').text
print(lastModifiedBy)
我还没有测试过它,但我希望相同的代码也能适用于其他OOXML文件(例如.docx
)
发布于 2019-12-15 04:23:51
抱歉,我来晚了,但这是我要做的。
import xlrd
wb = xlrd.open_workbook(a_file)
worksheet = wb.sheet_by_index(0)
mod_by = worksheet.book.props['last_modified_by']
发布于 2016-10-09 22:20:01
import os
filename = "C:\\test.xlsx"
statsbuf = os.stat(filename)
print "modified:",statsbuf.st_mtime
f = os.path.getmtime('C:\\test.xlsx')
print f
从一开始
https://stackoverflow.com/questions/39944495
复制相似问题