美文网首页
Python修改Excel

Python修改Excel

作者: 獨荹儛臨 | 来源:发表于2020-03-25 09:27 被阅读0次
    import openpyxl
    import json
    
    wb = openpyxl.load_workbook("/Users/kcl/Desktop/test.xlsx")
    print('输出文件所有工作表名:\n', wb.sheetnames)
    ws = wb['APP埋点事件']
    
    for index, i in enumerate(ws.iter_rows(min_row=2, min_col=3)):
        
        print(index)
        values = [cell.value for cell in i]
        
        if not values[2] is None:
    
            dict_json = json.loads(values[2])
            if dict_json: 
                value = dict_json['eventId']
                dict_json['eventId'] = values[1]
                str_json = json.dumps(dict_json)
                print(str_json)
                ws.cell(row =index+2, column=6).value = str_json
                
    wb.save("/Users/kcl/Desktop/test.xlsx")
    

    相关文章

      网友评论

          本文标题:Python修改Excel

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