需求:
取excel中数据生成用于插入数据库的SQL语句(当然也可以直接插入到数据库)。
步骤:
①安装xlrd,下载xlrd 解压,python setup.py install 安装
②编码
import xlrd
book = xlrd.open_workbook("d:/excel.xls")
sh = book.sheet_by_index(0)
for rx in range(sh.nrows):
rowdata = sh.row_values(rx)
name = rowdata[0]
sex = rowdata[1]
age = rowdata[2]
sql = "insert into tbName (name, sex, age) values ('"+name+"','"+sex+"','"+unicode(age)+"');"
print sql