立即注册 登录
通约社友 返回首页

admin的个人空间 http://su.sseuu.com/?1 [收藏] [复制] [分享] [RSS]

日志

2023-05-04

已有 81 次阅读2023-5-4 08:57

import openpyxl
from datetime import datetime, timedelta

# 定义固定日期
fixed_date = datetime(2023, 4, 2)

# 打开 Excel 文件
workbook = openpyxl.load_workbook('merged_file_2.xlsx')

# 选择工作表
worksheet = workbook.active

# 遍历列 G 中所有单元格,将日期转换成整数并减去固定日期,结果写入 H
for row in worksheet.iter_rows(min_row=2, min_col=7, max_col=7):
for cell in row:
cell_offset = cell.offset(column=1)
if cell.value is None:
continue
cell_date = cell.value.date()
cell_int = (cell_date - fixed_date.date()).days
cell_offset.value = cell_int

# 保存 Excel 文件
workbook.save('merged_file_2.xlsx')

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

小黑屋|Archiver|手机版|粤ICP备12005776号-5|su.sseuu.com  

GMT+8, 2025-7-3 23:43 , Processed in 0.049189 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2013 Comsenz Inc.

返回顶部