<pre name="code" class="python">#encoding=utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
#上面这三行为了防止python2.7 出现编码问题
import xlrd
book = xlrd.open_workbook(u"test.xlsx") #文件名,把文件与py文件放在同一目录下
sheet = book.sheet_by_name("test") #execl里面的表明
f = open("sql.txt","a")
for r in range(1, sheet.nrows): #第一行是我的标题名,对应表中的字段名所以应该从第二行开始,计算机以0开始计数,所以值是1
tel = int(sheet.cell(r,0).value)
uname = sheet.cell(r,1).value
branch = sheet.cell(r,2).value
str1 = "update tp_bind_emp SET " + "tel =" + "'" + str(tel) + "' "+ "where uname= " +"'" + uname + "' " + "and branch =" +"'" +branch + "' " + ";" +"\n";
str22 = str(str1)
f.write(str22)
print ""
print "Done! "
print ""
columns = str(sheet.ncols)
rows = str(sheet.nrows)
print '一共插入了 %s'% columns + '列' +'一共插入了 %s' % rows + '行'
python 批量写更新语句脚本
最新推荐文章于 2025-03-18 11:27:48 发布