Python脚本到SQL

2024-04-19 02:43:54 发布

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

我正在尝试使用python脚本来更新我的数据库。当我尝试运行脚本时,输出在字段的实际值之前显示text:或其他数据类型。有什么方法可以摆脱这个吗

for r in range(1, sheet.nrows):
    EasementNumber = (unicode(sheet.cell(r, 0)))
    Grantor = str(unicode(sheet.cell(r, 1)))
    Book = str(unicode(sheet.cell(r,2)))
    Page = str(unicode(sheet.cell(r,3)))
    Day = str(unicode(sheet.cell(r,4)))
    Month = str(unicode(sheet.cell(r,5)))
    Year = str(unicode(sheet.cell(r,6)))
    EasementType = str(sheet.cell(r,7))
    Origin = str(unicode(sheet.cell(r,8)))
    Descriptions = str(unicode(sheet.cell(r,9)))
    ProjectName = str(unicode(sheet.cell(r,10)))

    values = (EasementNumber, Grantor, Book, Page, Day, Month, Year, EasementType, Origin, Descriptions, ProjectName)

    cursor.execute(query, values)

cursor.close()

cursor.commit()

Tags: 脚本pageunicodecelloriginyearcursorsheet
1条回答
网友
1楼 · 发布于 2024-04-19 02:43:54

您正在将单元格对象转换为字符串,而不是使用cellvalue

您可以一次获取一行的所有值,而不是逐个读取单元格:

for row in range(1, sheet.nrows):
    values = sheet.row_values(row, 0, 11)
    cursor.execute(query, values)

相关问题 更多 >