python读取Excel数据,批量生成可执行的sql语句存入TXT文件
import pandas as pd
#读取excel文件数据
df = pd.read_excel('data.xlsx')
all_sql = ''
#生成sql语句
for index,row in df.iterrows():
#以update为例,可替换成其他操作sql语句
sql = "update table_name set field1={} where field2={};".format(row['field1'],row['field2'])
all_sql += sql
#写入txt
with open('sqls.txt','w') as f:
f.write(all_sql)