
from openpyxl import load_workbook #劉任昌指導蕭穎婕等學生專題
book = load_workbook(filename='wb.xlsx')
print(book.sheetnames) #列出所有工作表
"""以下也被註解暫時不執行python語言註解
#後面不執行 前後三個引號的部分也不執行 都是註解用
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 < 1 and dayC > (1 + criticalInc)*localL:
status = 1
elif status > -1 and dayC < (1 - criticalDes)*localH:
status = -1
sheet.cell(row = rowNo, column = 8).value = status
print(status)
book.save('result.xlsx')
"""

from openpyxl import load_workbook #劉任昌指導小仙女修程式設計
book = load_workbook(filename='wb.xlsx')
print(book.sheetnames) #列出所有工作表
#以下也被註解暫時不執行python語言註解
#後面不執行 前後三個引號的部分也不執行 都是註解用
sheet = book['劉任昌'] #工作表
sheet['A1'].value = '超級型男劉任昌python控制excel試算表'
rowBegin = 4 #起始列
rowEnd = 10 #結束列780先到10
criticalInc = 0.1
criticalDes = 0.1
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 < 1 and dayC > (1 + criticalInc)*localL:
status = 1
elif status > -1 and dayC < (1 - criticalDes)*localH:
status = -1
sheet.cell(row = rowNo, column = 8).value = status
book.save('result.xlsx') #結果另存為result.xlsx
https://kff0787.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://lin60616.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://pengyanyuu.blogspot.com/2023/06/pythonopenpyslexcel.html
回覆刪除https://xxddai.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://aik284267.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://d10950113.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://weizhezhantvsdexcr.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://d10917350.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://d10917257.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://tonydongdo.blogspot.com/2023/06/from-openpyxl-import-loadworkbook-book.html
回覆刪除https://xiang4427.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://d10917206.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://10917324.blogspot.com/2023/06/preborder-2px-orange-solid-from.html
回覆刪除https://d10917217.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除老師我要補交 EXCEL運算列表grid search獲得最佳參數https://d10917217.blogspot.com/2023/06/excelgrid-search.html
回覆刪除https://d10917225.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除作者已經移除這則留言。
回覆刪除https://dd10950104.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://d10917203.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://tsaihuajaker.blogspot.com/2023/06/excelgrid-search_8.html
回覆刪除https://hung927.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://dannyyeh13.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://kingmonkey2020.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://d10950132.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://tsaichingchung.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://kenyeh123.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://yanlin0320.blogspot.com/2023/06/python-openpyxlexcel.html
回覆刪除https://remonti0119.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://ruruuu23.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://chienchiwei.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://fyrjeike.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除https://weishinten.blogspot.com/2023/06/blog-post.html
回覆刪除https://dd10950104.blogspot.com/2023/06/blog-post.html
回覆刪除https://weishinten.blogspot.com/2023/06/pythonopenpyxlexcel.html
回覆刪除