非常沮丧的新Python用户。我曾经运行过一段代码,然后继续做一些其他的事情,现在它不起作用了。在
这是在.xlsx文件的“J”列中的非空白单元格中循环。对于包含文本的单元格,它查看列“A”中的日期。如果A列中的日期等于将来的7天,请打印“你该轮班了”
非常沮丧,因为它在某一点上工作,我不知道哪里出了问题。在workbook = load_workbook('FRANKLIN.xlsx', data_only=True)
ws=workbook.active
cell_range = ws['j1':'j100'] #Selecting the slice of interest
for row in cell_range: # This is iterating through rows 1-7
for cell in row: # This iterates through the columns(cells) in that row
value = cell.value
if cell.value:
if cell.offset(row=0, column =-9).value.date() == (datetime.now().date() + timedelta(days=7)):
print("you're due for a shift")
第二行到最后一行有这个错误。在
"AttributeError: 'str' object has no attribute 'date'"