政府采购网上传标书录入报价一览表
""" 此脚本功能为:解决政府采购网货物采购简化录入多项货物参数重复机械操作,只需一键导入。 操作步骤: 1、在original目录新建 price_data.xlsx,在excel表格编辑好需求录入的数据。 2、打开投标响应客户端,到指定项目制作标书,然后关闭客户端。 3、在投标响应客户端安装目录data文件夹下找到ProConfig.price文件,复制到original目录。 4、运行python文件。 5、打开result/NEW.ProConfig.price 文件,复制内容至投标响应客户端安装目录data文件夹下ProConfig.price文件。 6、打开投标响应客户端,找到报价一览表查看是否录入成功。 7、修改任意价格,再修改回原价,更新总价。 备注:python打包exe pyinstaller --onefile your_script.py """ import json,math,sys,os from openpyxl import load_workbook # 打开excel wb = load_workbook('original/price_data.xlsx') sheet = wb['price'] # 读取文件数据 with open('original/ProConfig.price', 'r',encoding='utf-8-sig') as file: content = json.loads(file.read()) # # 输入总价 # price_total = input('\033[33m' + "请输入总价:" + '\033[0m') # if price_total and price_total.replace('.','').isdigit(): # print('\033[32m' + f"您输入总价为:{price_total}" + '\033[0m') # # 修改总价至content # content['bjylb']['summaryData'][0]['data']= price_total # else: # print('\033[31m' + f"系统没有检测到输入的有效值,程序退出!" + '\033[0m') # sys.exit() # 获取源文件的bodyData数据 bodyData = content['bjylb']['resultData']['bodyData'] # excel表格列码 col_sheet_str = {"standardUnit":"A","goodsOriginPlace":"B","goodsBrand":"C","goodsModel":"D","goodsProducer":"E",} temporary_object = { #初始化临时对象 'sequence':{"dataType":"sequence","data_flag":False,"record_flag":True,"data":''}, # 序号 'detailName':{"dataType":"detailName","data_flag":False,"record_flag":True,"data":''}, # 商品名称 'numberMeasureUnit':{"dataType":"numberMeasureUnit","data_flag":False,"record_flag":False,"data":''}, # 数量 'maxLimitAmountUnit':{"dataType":"maxLimitAmountUnit","data_flag":False,"record_flag":True,"data":''}, # 最高限价 'standardUnit':{"dataType":"standardUnit","data_flag":True,"record_flag":False,"data":''}, # 报价 'priceModeName':{"dataType":"priceModeName","data_flag":False,"record_flag":False,"data":''}, # 报价形式 'goodsOriginPlace':{"dataType":"goodsOriginPlace","data_flag":True,"record_flag":False,"data":''}, # 生产地 'goodsBrand':{"dataType":"goodsBrand","data_flag":True,"record_flag":False,"data":''}, # 品牌 'goodsModel':{"dataType":"goodsModel","data_flag":True,"record_flag":False,"data":''}, # 规格型号 'goodsProducer':{"dataType":"goodsProducer","data_flag":True,"record_flag":False,"data":''}} # 生产厂家 # 处理bodyData数据 for index,data in enumerate(content['bjylb']['resultData']['bodyData']): index = index + 1 row_num = math.ceil(index/10) # 行号 col_num = index-(row_num-1)*10 # 列号 print(index, data) print('行号:', row_num, '列号:', col_num) if data['dataType'] == temporary_object[data['dataType']]['dataType']: # 处理报价数据 if temporary_object[data['dataType']]['record_flag']: # 将data值存入temporary_object v = data['data'] temporary_object[data['dataType']]['data'] = v print('\033[32m' + f"已将【{data['dataType']}:{v}】值存入temporary_object" + '\033[0m') if temporary_object[data['dataType']]['data_flag']: # 生成excel表格单元格坐标 cell_num = col_sheet_str[data['dataType']] + str(row_num) # 报价的时候处理数据 if data['dataType'] == "standardUnit": # 校验报价是否高于限价 data_insert = sheet[cell_num].value if data_insert <= int(float(temporary_object['maxLimitAmountUnit']['data'])): data_insert = str(data_insert) # 报价为int转str print('\033[32m' + f"报价【{data_insert}】校验通过" + '\033[0m') else: print('\033[31m' + f"【序号:{temporary_object['sequence']['data']},商品名称:{temporary_object['detailName']['data']}】报价高于限价,请修改。" + '\033[0m') sys.exit() else: data_insert = sheet[cell_num].value print("data_insert:",data_insert) data['data'] = data_insert print(data) # 写入数据到文件 file_path = "result/NEW.ProConfig.price" if os.path.exists(file_path): os.remove(file_path) print('\033[32m' + "成功删除历史文件【NEW.ProConfig.price】" + '\033[0m') with open(file_path, "a", encoding='utf-8') as file: file.write(json.dumps(content, ensure_ascii=False)) print('\033[32m' + "写入数据到新文件成功。Done." + '\033[0m')