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()
  • 相关阅读:
    编译安装mysql-5.6.36
    MYSQL数据库基础篇
    MYSQL数据库初学者必看
    Centos7下安装与卸载Jdk1.8
    Linux与Window之间的上传与下载
    MySQL主从搭建
    zabbix通过插件percona进行监控MySQL
    suse系统关闭防火墙
    编译安装zabbix3.0
    centos7安装tomcat
  • 原文地址:https://www.cnblogs.com/Jonecmnn/p/7660950.html
Copyright © 2011-2022 走看看