zoukankan      html  css  js  c++  java
  • Python Execl导入

    
    
    import xlrd

    from xlrd import open_workbook

    def
    getExeclInfo(filepath,colnameindex=0,by_index=0): data = xlrd.open_workbook(filepath) table = data.sheets()[by_index] # 行数 nrows = table.nrows # 列数 ncols = table.ncols colnames = table.row_values(colnameindex) list = [] for rownum in range(1,nrows): row = table.row_values(rownum) if row: app = {} for i in range(len(colnames)): app[colnames[i]] = row[i] list.append(app) return list
    数据插入
    def insertExeclInfo(list):
        session = db.session
        for dict in list:
            if list.index(dict) > 0:
                print(dict)
                try:
                    demo = models.Demo(id=dict['工号'],entrydate=dict['入职日期'],entryreasons=dict['入职原因'],RSscope=dict['人事范围'])
                    demotwo = models.DemoTwo(id = dict['工号'],surname = dict[''],name = dict[''],woman = dict[''],man = dict[''],birthdata = dict['出生日期'],birthcountry = dict['国籍'],maritalstatus = dict['婚姻状态'])
                    session.add(demotwo)
                    session.add(demo)
                except Exception as e:
                    return """<html><body><h1>数据插入异常</h1><p>Your chard could not
                     be charged. Please check the number and/or contact your credit card
                     company.</p></body></html>"""
        session.commit()
  • 相关阅读:
    oracle取字符串长度的函数length()和hengthb()
    文件操作
    numpy 库使用
    numpy 与 matplotlib 的应用过程
    使用numpy与matplotlib.pyplot画图
    面向对象的解读
    Python PIL
    Note of Jieba
    python 游戏 —— 汉诺塔(Hanoita)
    有进度条圆周率Π计算
  • 原文地址:https://www.cnblogs.com/Jonecmnn/p/7660950.html
Copyright © 2011-2022 走看看