1 Star 0 Fork 0

Error丶log / excle-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
excle.py 2.38 KB
一键复制 编辑 原始数据 按行查看 历史
Error丶log 提交于 2021-05-19 23:24 . s
import xlrd
import pymysql
fname = r'C:\Users\Administrator\Desktop\1.xls'
filename = xlrd.open_workbook(fname)
sheets = filename.nsheets
sheet_list = filename.sheet_names()
sheet = filename.sheets()[0]
nrows = sheet.nrows
ncols = sheet.ncols
# mysql保存数据
def saveDataDB(list1, list2, list3, list4, list5, list6, list7, list8, list9):
conn = pymysql.connect(host='127.0.0.1', port=3306, user='python', password='Mysql_123', db='python', charset='utf8')
cur = conn.cursor()
sql = '''
insert into COMPANY_FINACING_test (
company_name,date_time,product_name,financing_round,valuation_amount,amount_of_financing,investment_institution,news_link,page_address)
values(("%s"),("%s"),("%s"),("%s"),("%s"),("%s"),("%s"),("%s"),("%s"))''' % (list1, list2, list3, list4, list5, list6, list7, list8, list9)
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print('保存数据库成功!!')
# 创建数据表
def init_db():
sql = '''
create table COMPANY_FINACING_test
(
id int PRIMARY KEY AUTO_INCREMENT,
company_name char(200) ,
date_time char(100),
product_name char(100),
financing_round char(100),
valuation_amount char(100),
amount_of_financing char(100),
investment_institution char(250),
news_link char(250),
page_address char(200)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
''' # 创建表结构
conn = pymysql.connect(host='127.0.0.1', port=3306, user='python', password='Mysql_123', db='python', charset='utf8')
cursor = conn.cursor()
cursor.execute(sql)
conn.commit()
conn.close()
def run():
row_list = []
for i in range(0, nrows):
row_datas = sheet.row_values(i)
row_list.append(row_datas)
for x in range(0, 1472):
list1 = row_list[x][0]
list2 = row_list[x][1]
list3 = row_list[x][2]
list4 = row_list[x][3]
list5 = row_list[x][4]
list6 = row_list[x][5]
list7 = row_list[x][6]
list8 = row_list[x][7]
list9 = row_list[x][8]
saveDataDB(list1, list2, list3, list4, list5, list6, list7, list8, list9)
def main():
init_db()
run()
if __name__ == "__main__":
main()
1
https://gitee.com/eroor/excle-mysql.git
git@gitee.com:eroor/excle-mysql.git
eroor
excle-mysql
excle-mysql
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891