美文网首页
操作excel

操作excel

作者: __method__ | 来源:发表于2021-02-18 14:47 被阅读0次
    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')
    

    相关文章

      网友评论

          本文标题:操作excel

          本文链接:https://www.haomeiwen.com/subject/uwzgxltx.html