python excel导入到数据库

it2022-05-09  26

import xlrd import MySQLdb def inMySQL(file_name): wb = xlrd.open_workbook(file_name) sh = wb.sheet_by_index(0) data = [sh.row_values(row) for row in range(0,sh.nrows)] db = MySQLdb.connect("localhost","root","123","STUDENTS",use_unicode=1, charset='utf8') cursor = db.cursor() sql ='''INSERT INTO students VALUES(%s,%s,%s,%s,%s,%s)''' cursor.executemany(sql,data) db.commit() cursor.close() db.close() if __name__=="__main__": inMySQL('/home/wangzhch/test.xls')

 

转载于:https://www.cnblogs.com/iwangzhch/p/3988574.html

相关资源:python3导入excel数据到mysql例子

最新回复(0)