EXCEL data into the database of the python

Basic Operation undertake the above database operations, well, directly on the code

# Excel导入数据库处理
    tables = load_workbook(filename='Database/stud.xlsx')
    # 获取表内容
    data = tables.worksheets[0]
    rows = data.max_row
    cols = data.max_column
    sql = 'insert into stu (name, age) values (?, ?)'
    xl_data = []
    for rx in range(2, rows+1):
        for cx in range(1,cols+1):
            xl_data.append(str(data.cell(row=rx, column=CX) .Value)) 
        OB = [(xl_data [0], xl_data [. 1 ])] 
        T = db.execute_update (SQL, OB)
         IF T:
             Print ( ' ! insertion success ' )
         the else :
             Print ( ' insert failed! ' ) 
        xl_data = []

This can be a simple write strategy

Guess you like

Origin www.cnblogs.com/pythoncoder/p/11031136.html