使用python3编写代码比对excle表格中的日期

表格类似如下:

使用python3编写代码比对excle表格中的日期_第1张图片

需要提取H列和I列的日期,并且进行日期分割,提取出日期,将日期倒置,倒置后,拿 关闭时间减去创建时间,得出超过3天的数据,提取出相应的行:

# #-* -编码: utf-8-* -
import xlrd
from datetime import datetime


biaoge="""表格.xls"""
tangfiles=xlrd.open_workbook(biaoge)

table1=tangfiles.sheet_by_index(0)
#行的操作

nrows=table1.nrows
ncols = table1.ncols


# print(ncols) #列
print("==============================================================================================================================================================================")
for i in range(1,111):
    #print(i)
    xi=table1.row(i)
    start_date0 = (str(table1.col_values(7)[i]).split("@"))[0]
    start_date1 = (start_date0).split("-")
    start_date= "2023"+"-"+start_date1[0]+"-"+start_date1[1]
    end_date0 = (str(table1.col_values(8)[i]).split("@"))[0]
    end_date1 = end_date0.split("-")
    end_date = "2023"+"-"+end_date1[0]+"-"+end_date1[1]

    start_datetime = datetime.strptime(start_date, "%Y-%m-%d")
    end_datetime = datetime.strptime(end_date, "%Y-%m-%d")
    delta = end_datetime - start_datetime

    days = delta.days

    if days > 2 :
        print("第"+str(i+1)+"行:")
        print("日期大于2天,日期为天 ",days)

        print(xi)
        print("----------------------------------------------------------------------------------------------------------------------------------------")


print("                                      ")
print("==============================================================================================================================================================================")

你可能感兴趣的:(python,numpy,开发语言)