主要看加注释的
import xlrd
from xlutils.copy import copy
#读取excel
excel = xlrd.open_workbook(r'C:\Users\wk\Desktop\222.xls')
#cp对象
wb = copy(excel)
#读取工作表
sheets = excel.sheets()[0]
#读取工作表
w_sheet = wb.get_sheet(0)
i = 1
lastrow = 0.0
next_line = 0
iszero = 0
#循环
for a in range(sheets.nrows):
#获取值 a 为行号 1表示从0 开始 第二列
line = sheets.row_values(a)[1]
if ".00" in str(line):
iszero = 1
continue
if 1 == iszero:
print((lastrow+float(line))/2)
#修改数据 w_sheet.write(行号,列号,值)
w_sheet.write(a-1,1,round((lastrow+float(line))/2,2))
iszero = 0
lastrow = float(line)
#保存到新的excel中
wb.save(r'C:\Users\wk\Desktop\new.xls')
# if isHaveStr in str(line):
# print(line + " "+ str(a+1) + " "+str(sheets.row_values(a)[2]))