1、目的:获取如下数据
文件:
2、代码
import datetime
from openpyxl import load_workbook
import pandas as pd
import os
def getExcelMetadata(root,files):
# 获取文件的时间属性
a1,a2,a3 = [],[],[]
for file_name in files:
wb = load_workbook(root+"/"+file_name)
a1.append((wb.properties.created+datetime.timedelta(hours=+8)).strftime('%Y-%m-%d %H:%M'))
a2.append((wb.properties.modified+datetime.timedelta(hours=+8)).strftime('%Y-%m-%d %H:%M'))
a3.append((wb.properties.lastPrinted+datetime.timedelta(hours=+8)).strftime('%Y-%m-%d %H:%M'))
pd.DataFrame({"文件名":pd.Series(files),"创建时间":pd.Series(a1),"保存时间":pd.Series(a2),"打印时间":pd.Series(a3)}).to_excel("date.xlsx",index=False)
path = r"data" # 将文件放在这个文件夹
files = os.listdir(path)
# 格式不统一无法处理,统一文件后缀格式
for filename in files:
print(filename)
portion = os.path.splitext(filename)
if portion[1] == ".xls":
newname = portion[0] + ".xlsx"
os.rename(path + "/" + filename, path + "/" + newname)
getExcelMetadata(root=path,files=files)