excel数据未使用python上载到mysql workbench

2024-10-03 00:17:28 发布

您现在位置:Python中文网/ 问答频道 /正文

数据未上载到mysql workbench

我查了mysql工作台

import xlrd
import pymysql

book = xlrd.open_workbook("c:/Temp/exportimport201006.xls")
sheet = book.sheet_by_name("201006")

database = pymysql.connect(host = 'xxx', user = 'xxx', password = 'xxx', db = 'xxx')
cursor = database.cursor()
query = """INSERT INTO exportimport (year, hscode, expwgt, expdlr, impwgt, impdlr, balpayments) VALUES (%s, %s, %s, %s, %s, %s, %s)"""

for r in range(2, sheet.nrows):
    year = sheet.cell(r,0).value
    hscode = sheet.cell(r,1).value
    expwgt = sheet.cell(r,2).value
    expdlr = sheet.cell(r,3).value
    impwgt = sheet.cell(r,4).value
    impdlr = sheet.cell(r,5).value
    balpayments = sheet.cell(r,6).value

    values = (year,hscode,expwgt,expdlr,impwgt,impdlr,balpayments)
    cursor.execute(query, values)

database.close()

虽然数据量不大,但还没有完成

哪一部分错了

我是Python初学者


Tags: importvaluemysqlcellyearcursordatabasesheet