简体   繁体   English

如何使用 xlrd 获取 .xls 文件的修改日期

[英]How to get the modified date of an .xls file using xlrd

Let me try to improve this question, as it is still valid for me.让我试着改进这个问题,因为它对我来说仍然有效。

I have been using Openpyxl to read Excel files for a while.我一直在使用 Openpyxl 来读取 Excel 文件。 Now I need to extend the capability of my script to handle "legacy" Excel files that are not supported by Openpyxl.现在我需要扩展我的脚本的功能来处理 Openpyxl 不支持的“遗留”Excel 文件。 For this I use xlrd and xlutils.为此,我使用 xlrd 和 xlutils。

On issue I have yet to solve is how to get the modified date of an .xls file in the case where I don't have the path.我尚未解决的问题是如何在没有路径的情况下获取 .xls 文件的修改日期。 Using Openpyxl, I can get this as Workbook.properties.modified, as a datetime object.使用 Openpyxl,我可以将其作为 Workbook.properties.modified,作为日期时间对象。 With xlrd I am struggling.使用 xlrd 我很挣扎。 A workaround would be to figure out the path to the file (which may be input to my function as a file like object) and to use os.path.getmtime , but I am not sure if that is equivalent.一种解决方法是找出文件的路径(它可以作为一个类似对象的文件输入到我的函数中)并使用os.path.getmtime ,但我不确定这是否等效。

Any help is appreciated!任何帮助表示赞赏!

I just came across your post while searching for a solution myself.我刚刚在自己寻找解决方案时看到了您的帖子。 Seems like似乎

wb = xlrd.open_workbook(filename=fn)
wb.props.get('modified')

does the job.做这项工作。

xlrd==1.2.0 xlrd==1.2.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM