from openpyxl import load_workbook #王薰珮指導蕭穎婕等學生專題 book = load_workbook(filename='pylenin.xlsx') sheet = book['20200101p'] #工作表 rowBegin = 4 #起始列 rowEnd = 10 #結束列780 criticalInc = 0.01 criticalDes = 0.01 localH = sheet.cell(row=rowBegin, column=3).value localL = sheet.cell(row=rowBegin, column=4).value status = 0 wealth = 0 for x, row in enumerate(sheet.iter_rows(min_row = rowBegin, max_row = rowEnd)): rowNo = x + rowBegin #串列編號 x 起始於 0 dayH = row[2].value #當日最高C欄 dayL = row[3].value #當日最低D欄 dayC = row[4].value #當日收盤E欄 if status == -1: #檢測波段高 localH = dayH elif localH < dayH: localH = dayH if status == 1: #檢測波段低 localL = dayL elif localL > dayL: localL = dayL sheet.cell(row = rowNo, column = 6).value = localH #寫入波段高於F欄 sheet.cell(row = rowNo, column = 7).value = localL #寫入波段低於G欄 if status