#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("\t\t\t\t\tA."+str(sourceTabCol[i]).upper()+" "+str(destTabCol[i]).upper()+",\n") 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("\t\t\t\t\tSYSDATE "+toSureColArray[i]+",\n") destTableSureArray.append(toSureColArray[i]) #定义子sheet目标数据插入函数主键模块 #入参为文件描述符、源表列字段、目表源字段 def childSheetColDesKeyFunc(fOutput, sourceTabCol, destTabCol): #如果为空表,此处会报下标溢出错误,所以入参必须保证表中有数据 if len(sourceTabCol[2]) != 0: fOutput.write("\t\t\t\t["+str(destTabCol[2]).upper()+"]\n") fOutput.write("\t\t\t\t[STATEFLAG]\n") #定义子sheet目标函数插入函数非主键模块 def childSheetColDesNKeyFunc(fOutput, sourceTabCol, destTableSureArray): if len(sourceTabCol[2]) != 0: for i in range(1,len(destTableSureArray)): fOutput.write("\t\t\t\t["+destTableSureArray[i]+"]\n") else: for i in range(0,len(destTableSureArray)): fOutput.write("\t\t\t\t["+destTableSureArray[i]+"]\n") #定义子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("\n") fOutput.write("\n") fOutput.write("\t\n") fOutput.write("\t\t\n") fOutput.write("\t\t\t\n") fOutput.write("\t\t\n") fOutput.write("\t\t\n") childSheetColDesKeyFunc(fOutput, zhizhenTabCol, langchaoTabCol) fOutput.write("\t\t\t\n") fOutput.write("\t\t\t\n") childSheetColDesNKeyFunc(fOutput, zhizhenTabCol, destTableSureArray) fOutput.write("\t\t\t\n") fOutput.write("\t\t\n") fOutput.write("\t\n") fOutput.write("\n") 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)

sheet目标数据插入函数主键模块的更多相关文章

  1. mybatis的插入数据后的主键获取

    为什么要在插入数据后获取主键:当有一个订单表和订单详情表,当插入订单表的数据后,需要在订单详情表插入该订单的具体购物情况,订单详情表需要的一个列是订单表的主键或者订单ID.(通俗讲:A表的主键是B表的 ...

  2. 数据库插入数据返回当前主键ID值方法

    当我们插入一条数据的时候,我们很多时候都想立刻获取当前插入的主键值返回以做它用.我们通常的做法有如下几种: 1. 先 select max(id) +1 ,然后将+1后的值作为主键插入数据库: 2. ...

  3. mysql insert插入时实现如果数据表中主键重复则更新,没有重复则插入的四种方法

    [CSDN下载] Powerdesigner 设计主键code不能重复等问题 [CSDN博客] Oracle中用一个序列给两个表创建主键自增功能的后果 [CSDN博客] MySQL自增主键删除后重复问 ...

  4. ibatis实战之插入数据(自动生成主键)

    ibatis实战之插入数据(自动生成主键) --------- 如果你将数据库设计为使用自动生成的主键,就可以使用ibatis的<selectKey>元素(该元素是<insert&g ...

  5. Laravel 5 插入数据后返回主键ID

    方法一: $info = DB::table('表名')->insertGetId(['imgName' => $fileName]);//图片名入库后返回添加数据行的主键ID 方法二:( ...

  6. Java中获取刚插入数据库中的数据Id(主键,自动增长)

    public int insert(String cName, String ebrand, String cGender) { String sql = "insert into Clot ...

  7. mybatis 插入数据并返回主键值

    <insert id="insert" parameterType="com.pojo.TSubject" useGeneratedKeys=" ...

  8. MyBatis+MySQL 返回插入的主键ID

    需求:使用MyBatis往MySQL数据库中插入一条记录后,需要返回该条记录的自增主键值. 方法:在mapper中指定keyProperty属性,示例如下: <insert id="i ...

  9. PHP获取新插入的主键id

    近期在做订单系统开发的时候遇到了此类情景,A表内插入后返回新插入的主键ID,然后用于B表插入数据并携带此id. 目前有几个方法总结 No1.每次插入数据之后返回A表内的最大值,但是对于多用户以及高并发 ...

随机推荐

  1. 多个list合并

    需要多个list合并,如图 @SuppressWarnings("unchecked")    @Override    public List<CwInfo> get ...

  2. intellij 提交代码到git

    .配置git .create git repository .git-->add commit Directory .提交代码 git remote add origin https://git ...

  3. Ubuntu下自动挂载分区

    参考文章:http://feierky.iteye.com/blog/1998602 1.查看分区的UUID sudo blkid /dev/sda1: UUID="3526b254-390 ...

  4. win + linux + android 多任务分屏

    Win10 的多任务分屏操作方法_百度经验http://jingyan.baidu.com/article/48206aeaf6ef35216ad6b336.html win+方向键 如果是想四分屏幕 ...

  5. Java Hour 32 Weather ( 5 ) struts2 – Action class

    有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. Hour 32 Struts2 Action 1 将action 映射到 ac ...

  6. hdu 3746 kmp求循环节

    题意就是将所给的字符串变成多个完整的循环(至少两个),然后给出最少需要添加的字符数.

  7. C++的那些事:类的拷贝控制

    1,什么是类的拷贝控制 当我们定义一个类的时候,为了让我们定义的类类型像内置类型(char,int,double等)一样好用,我们通常需要考下面几件事: Q1:用这个类的对象去初始化另一个同类型的对象 ...

  8. hihoCoder挑战赛14 -1223

    描述 给定n个关于X的不等式,问最多有多少个成立. 每个不等式为如下的形式之一: X < C X <= C X = C X > C X >= C 输入 第一行一个整数n. 以下 ...

  9. ToggleButton

    <ToggleButton android:id="@+id/toggle" android:layout_width="wrap_content" an ...

  10. JavaScript案例四:全选练习

    JavaScript实现全选,全不选等效果... <!DOCTYPE html> <html> <head> <title>JavaScript全选练习 ...