操作excel

2021-02-18  本文已影响0人  __method__
from openpyxl.styles import PatternFill
import openpyxl
wb = openpyxl.load_workbook('^HSI.xlsx')
ws = wb.active
before_value = ws['F2'].value
print(before_value)
print(type(before_value))
for index, cell in enumerate(ws['F'][2:]):
    current_value = cell.value
    if current_value >= before_value:
        # 漲了 red
        fill = PatternFill("solid", fgColor="CD0000")
        ws['F{}'.format(index + 3)].fill=fill
        ws['H{}'.format(index + 3)] = 'UP'

        before_value = current_value
    else:
        fill = PatternFill("solid", fgColor="9AFF9A")
        ws['F{}'.format(index + 3)].fill=fill
        ws['H{}'.format(index + 3)] = 'DOWN'

        before_value = current_value
    # print(index+2, "--->", cell.value)
#保存文件
wb.save('^HSI.xlsx')
上一篇下一篇

猜你喜欢

热点阅读