2017-02-17 39 views
-2

我想用python脚本来更新我的数据库。当我尝试运行脚本时,输出表示text:或其他数据类型,在该字段的实际值之前。任何提示如何摆脱这个?Python脚本到SQL Server

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() 
+1

没有代码,没有人可以说,为什么你看到'文本:' – Daniel

+0

添加的代码示例。 –

回答

0

要转换细胞的对象为字符串,而不是使用cellvalue

而不是逐个读取细胞,就可以得到一个行的所有值一次:

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

谢谢!这有助于很多! –