zoukankan      html  css  js  c++  java
  • sheet目标数据插入函数主键模块

    #coding:gbk #导入处理excel的模块 import xlrd #定义哪些字段需要判断,只支持时间字段 toSureColArray = ['CREATE_TIME','MODIFY_TIME'] #确定某个字段是否在数组中 def isColInArray(colName, colArray): for i in range(0, len(colArray)): if (colName == colArray[i]): return 1 else: return 0 #定义子sheet字段属性映射处理函数 #入参为文件描述符、、源表列字段、和目表列字段 def childSheetColFunc(fOutput, sourceTabCol, destTabCol,destTableSureArray): for i in range(2,len(sourceTabCol)): if len(destTabCol[i]) != 0: if len(sourceTabCol[i]) != 0: #在子表中,如果浪潮int_id对应的直真字段英文名称为空,在destTableSureArry不存在INT_ID属性 destTableSureArray.append(str(destTabCol[i]).upper()) fOutput.write(" A."+str(sourceTabCol[i]).upper()+" "+str(destTabCol[i]).upper()+", ") else: continue else: continue #for i in range(0,len(destTableSureArray)): # print("******************") # print(str(destTableSureArray[i])) # print("******************") #对creat_time和modify_time做单独处理 for i in range(0,len(toSureColArray)): if isColInArray(toSureColArray[i],destTableSureArray) == 0: fOutput.write(" SYSDATE "+toSureColArray[i]+", ") destTableSureArray.append(toSureColArray[i]) #定义子sheet目标数据插入函数主键模块 #入参为文件描述符、源表列字段、目表源字段 def childSheetColDesKeyFunc(fOutput, sourceTabCol, destTabCol): #如果为空表,此处会报下标溢出错误,所以入参必须保证表中有数据 if len(sourceTabCol[2]) != 0: fOutput.write(" ["+str(destTabCol[2]).upper()+"] ") fOutput.write(" [STATEFLAG] ") #定义子sheet目标函数插入函数非主键模块 def childSheetColDesNKeyFunc(fOutput, sourceTabCol, destTableSureArray): if len(sourceTabCol[2]) != 0: for i in range(1,len(destTableSureArray)): fOutput.write(" ["+destTableSureArray[i]+"] ") else: for i in range(0,len(destTableSureArray)): fOutput.write(" ["+destTableSureArray[i]+"] ") #定义子sheet处理函数 def childSheetFunc(sheetName, sourceTable, destTable): #根据sheet名打开表 shtInstance=workBook.sheet_by_name(sheetName) #存放最终哪些浪潮字段需要映射 destTableSureArray = [] langchaoTabCol=shtInstance.col_values(4) zhizhenTabCol=shtInstance.col_values(6) print("***********现在开始生成"+str(destTable).upper()+".xml 文件***********") path="e:\"+destTable.upper()+".xml" fOutput=open(path,"w") fOutput.write(" ") fOutput.write(" ") fOutput.write(" ") fOutput.write(" ") fOutput.write(" ") fOutput.write(" ") fOutput.write(" ") childSheetColDesKeyFunc(fOutput, zhizhenTabCol, langchaoTabCol) fOutput.write(" ") fOutput.write(" ") childSheetColDesNKeyFunc(fOutput, zhizhenTabCol, destTableSureArray) fOutput.write(" ") fOutput.write(" ") fOutput.write(" ") fOutput.write(" ") fOutput.close() print("***********"+str(destTable).upper()+".xml 文件生成完成***********") #根据主表获取子表信息并处理 def mainSheetAndProc(mainSheet): sheetName=mainSheet.col_values(2881064151) sourceTabName=mainSheet.col_values(5) destTabName=mainSheet.col_values(3) curNum = 0 for i in range(2,len(sheetName)): if len(sheetName[i]) ==0: continue curNum += 1 print(">>>>>>开始生成第"+str(curNum)+"个文件") childSheetFunc(sheetName[i], sourceTabName[i], destTabName[i]) #入口函数 if __name__=="__main__": workBook=xlrd.open_workbook("E:\内线比对模型.xls") mainSheet=workBook.sheets()[0] mainSheetAndProc(mainSheet) 

  • 相关阅读:
    AcWing 157. 树形地铁系统 (hash判断树同构)打卡
    AcWing 156. 矩阵 (哈希二维转一维查询)打卡
    AcWing 144. 最长异或值路径 01字典树打卡
    AcWing 143. 最大异或对 01字典树打卡
    AcWing 142. 前缀统计 字典树打卡
    AcWing 139. 回文子串的最大长度 hash打卡
    AcWing 138. 兔子与兔子 hash打卡
    常用C库函数功能及用法
    编程实现C库函数
    C语言面试题5
  • 原文地址:https://www.cnblogs.com/cbryge/p/6098867.html
Copyright © 2011-2022 走看看