码迷,mamicode.com
首页 > 其他好文 > 详细

操作文件Excel(xlsx格式)

时间:2019-06-13 20:46:35      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:import   content   range   ota   nod   model   edits   roc   alc   

import json

import requests
from openpyxl import load_workbook
#创建文件对象
wb = load_workbook("thirdData.xlsx")
ws = wb.active
print(ws.title)


for i in range(1,8):
    url = "http://var-derived.common.jc1.jieyue.com/api/invokeRuleFlow"

    data = {
        "sysCode": "loan",
        "frontTransNo": "id0001",
        "frontTransTime": "2019-05-2900:00:00",
        "rulePackage": "资产规则集/creditScoreCard3",
        "processId": "creditCardThree",
        "facts": {"TongDunInfo": {
                "className": "com.jieyue.urule.entity.TongDunInfoDTO",
                "phoneNodeScore":ws["D"+str(i)].value,  #获取文件的值
                "idBlackRat": ws["D"+str(i+7)].value,
                "idTotalCnt": ws["D"+str(i+14)].value,
                "phoneBlackCnt":ws["D"+str(i+21)].value,
                "homePhoneNodeScore":ws["D"+str(i+28)].value,"idNodeScore": 1
            },"ScoreCardModelVO": {
                "className": "com.jieyue.urule.entity.ScoreCardModelVO"
            }
        }
    }
    headers = {"Content-Type": "application/json"}
    req = requests.post(url=url, data=json.dumps(data), headers=headers)
    res = json.loads(req.content)
#写入文件
    ws["H"+str(i)].value = res[responseBody][facts][TongDunDerivedInfo][phoneNodeScore]
    ws["H"+str(i+7)].value = res[responseBody][facts][TongDunDerivedInfo][idBlackRat]
    ws["H"+str(i+14)].value = res[responseBody][facts][TongDunDerivedInfo][idTotalCnt]
    ws["H"+str(i+21)].value = res[responseBody][facts][TongDunDerivedInfo][phoneBlackCnt]
    ws["H"+str(i+28)].value = res[responseBody][facts][TongDunDerivedInfo][homePhoneNodeScore]
    wb.save("thirdData.xlsx")

 

操作文件Excel(xlsx格式)

标签:import   content   range   ota   nod   model   edits   roc   alc   

原文地址:https://www.cnblogs.com/bubutianshu/p/11018922.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!