You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python 2获取Excel文件属性(作者、最后保存/打印时间)

How to Extract Excel Document Properties (Author, Last Save/Print Time) in Python 2

Hey there! The os.path module only gives you filesystem-level metadata (like access or modify time)—that’s not the same as the document-specific properties stored inside the Excel file itself. To get those details like author, last save time, or last print time, you’ll need a library that can parse the Excel file’s internal structure. Here’s how to do it for both common Excel formats:

For .xls Files (Excel 97-2003)

Use the xlrd library (version 1.2.0 is the last release that supports Python 2). First, install it via pip:

pip install xlrd==1.2.0

Then use this code to extract the properties:

import xlrd

file_path = "your_file.xls"
workbook = xlrd.open_workbook(file_path)

# Get document properties
props = workbook.doc_properties
print("Author:", props.author)
print("Last saved time:", props.last_saved_date)
print("Last printed time:", props.last_printed_date)

Note: last_printed_date might return None if the file was never printed, or if the property wasn’t saved by the Excel version used.

For .xlsx Files (Excel 2007+)

Use openpyxl (version 2.6.4 is the last release compatible with Python 2). Install it with:

pip install openpyxl==2.6.4

Then extract the properties like this:

from openpyxl import load_workbook

file_path = "your_file.xlsx"
workbook = load_workbook(file_path, read_only=True)

# Access core properties
core_props = workbook.properties
print("Author:", core_props.creator)
print("Last saved time:", core_props.modified)

# Access extended properties (for last print time)
ext_props = workbook.extended_properties
print("Last printed time:", ext_props.get('lastPrinted'))

Again, lastPrinted might be None if the property isn’t set in the file.

Important Notes

  • Make sure to install the exact versions specified—newer releases of these libraries dropped support for Python 2 entirely.
  • Some properties might be missing depending on how the Excel file was saved (e.g., if the user disabled saving metadata in Excel settings).

内容的提问来源于stack exchange,提问作者András P.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:56:57