python之EXCEL数据导入数据库
时间:2021-07-01 10:21:17
帮助过:4人阅读
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(
‘插入成功!‘)
else:
print(
‘插入失败!‘)
xl_data = []
这样就可以进行简单的写入咯
python之EXCEL数据导入数据库
标签:获取 pytho upd exce class python value work name