python在excel中遍历存储语句

#1,启动excel
app = xw.App(visible=False, add_book=False)
wb = xw.Book(save_excel_path)
sht = wb.sheets[0]

#2,写入表头
sht.range('A1').value = 'num'        # 向A1单元格写入该行数据lable  如:CK-1
sht.range('B1').value = 'file_new'  # 向B1单元格写入该行数据lable  如:CK-1_1
sht.range('C1').value = 'r_min'     # 向C1单元格写入该行数据lable  如:r_min
sht.range('D1').value = 'r_max'     # 向D1单元格写入该行数据lable
sht.range('E1').value = 'g_min'     # 向E1单元格写入该行数据lable
sht.range('F1').value = 'g_max'     # 向F1单元格写入该行数据lable
sht.range('G1').value = 'b_min'     # 向G1单元格写入该行数据lable
sht.range('H1').value = 'b_max'     # 向H1单元格写入该行数据lable
sht.range('I1').value = 'r_mean'    # 向i1单元格写入该行数据lable
sht.range('J1').value = 'g_mean'    # 向j1单元格写入该行数据lable
sht.range('K1').value = 'b_mean'    # 向k1单元格写入该行数据lable

#3,循环写入列
save_name = os.path.join('B' + str(j + 2))     #j为循环次数,从B2位置开始顺序存入列
sht.range(save_name).options(transpose=True).value = file_new  # 从b2单元格开始存入

#4,循环写入行
save_num = os.path.join('C' + str(N+2) + ':' + 'K' + str(N+2))   #从C2:K2循环存放行,共存放32行数据(果实存放了32天)
sht.range(save_num).value = [r_min, r_max, g_min, g_max, b_min, b_max, r_mean, g_mean, b_mean]  # 从C2:K2单元格开始存入一行

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值