-- coding:utf-8 --
import pymysql
import xlrd
连接数据库
try:
db = pymysql.connect(host=‘192.168.0.157’, user=“kedacom”, passwd=“kedacom@123”, db=‘ismp_cardmng’, port=3306, charset=‘utf8’)
except:
print(“could not connect to mysql server”)
def open_excel():
try:
book = xlrd.open_workbook(“dev.xlsx”) # 文件名,把文件与py文件放在同一目录下
except Exception as e:
print(e)
try:
sheet = book.sheet_by_name(“Sheet1”) # execl里面的Sheet1为使用
return sheet
except Exception as e:
print(e)
def insert_deta():
sheet = open_excel()
cursor = db.cursor()
row_num = sheet.nrows
print(row_num)
for i in range(1, row_num): # 第一行是标题名,对应表中的字段名所以应该从第二行开始,计算机以0开始计数,所以值是1
row_data = sheet.row_values(i)
print(row_data)
value = (row_