工作纪实_32-倒排期需求python实用性上场

产品提了一个倒排期需求,业务完成度和时间都有一定要求;必须完成,且有一部分数据是通过excel进行导入,且数据不算太大,但是列很多,一个月导一次

为了更好的将精力放在业务实现上,因此写了一个python来处理这种数据导入的问题,java写实在是太麻烦了,不管是POI还是easyExcel,而且最主要是这个后面完全会调三方接口来做,只是一个过渡期,大pyhton上场

import json
import os

import openpyxl

def file_save(str):
    File_Name = "target.txt"
    if os.path.exists(File_Name):
        os.remove(File_Name)
    with open(File_Name, 'a') as file_object:
        file_object.write("{}".format(str))
    pass

excel = openpyxl.load_workbook(filename="excel.xlsx")
## 获取表格sheet页名称
sheet_name = excel.sheetnames
print("sheet:", sheet_name)

## 获取sheet对象
sheet_obj = excel.worksheets
## 读取excel 信息
json_array = []
for sheet in sheet_obj:

    ## 获取标题
    sheet_obj_title = sheet.title
    sheet_obj_max_row = sheet.max_row
    sheet_obj_max_column = sheet.max_column
    print("sheet的标题:", sheet_obj_title, "行数:", sheet_obj_max_row, "列数:", sheet_obj_max_column)
    ## 读取每行数据
    for rowIndex in range(2, sheet_obj_max_row + 1):
        shop_name = sheet.cell(row=rowIndex, column=1).value
        shop_id = sheet.cell(row=rowIndex, column=2).value
        month = sheet.cell(row=rowIndex, column=3).value
        target_A = sheet.cell(row=rowIndex, column=4).value
        target_B = sheet.cell(row=rowIndex, column=5).value
        target_C = sheet.cell(row=rowIndex, column=6).value
        json_obj = {
            "customer_shop_name": shop_name,
            "customer_shop_id": shop_id,
            "year_month": month,
            "kpi_goal": target_A,
            "gross_profit_goal": target_B,
            "send_order_goal": target_C
        }
        json_array.append(json_obj)
    print(json_array)
file_save(json.dumps(json_array, ensure_ascii=False))
 [{"shop_id": 423, "year_month": 1, "kpi_goal": 1000, "gross_profit_goal": 1100, "send_order_goal": 1200}, {"shop_id": 586, "year_month": 2, "kpi_goal": 2000, "gross_profit_goal": 2100, "send_order_goal": 2200}]

写个插入接口,齐活!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值