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

 

转载于:https://www.cnblogs.com/Jonecmnn/p/7660950.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值