• 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) 

  • 相关阅读:
    P1270 【“访问”美术馆】
    SP14932 【LCA
    NOI 题库 9272 题解
    Code[VS] 1230 题解
    20161022 NOIP模拟赛 T1 解题报告
    20161023 NOIP 模拟赛 T2 解题报告
    20161023 NOIP 模拟赛 T1 解题报告
    20161022 NOIP模拟赛 解题报告
    POJ 1979 题解
    POJ 1160 题解
  • 原文地址:https://www.cnblogs.com/cbryge/p/6098867.html
Copyright © 2020-2023  润新知