第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用Python 語句將excel 自動導(dǎo)入本地Mysql數(shù)據(jù)表, 顯示執(zhí)行完畢,但Mysql 數(shù)據(jù)表中沒有找到紀(jì)錄

使用Python 語句將excel 自動導(dǎo)入本地Mysql數(shù)據(jù)表, 顯示執(zhí)行完畢,但Mysql 數(shù)據(jù)表中沒有找到紀(jì)錄

慕勒13948 2019-04-29 13:30:55
各位高手好:在嘗試著把之前自己的工作紀(jì)錄導(dǎo)進本機建立的Mysql 數(shù)據(jù)庫中網(wǎng)上找到了某大神的代碼:?如連接:?https://www.cnblogs.com/longbigbeard/p/9309180.html運行代碼后顯示運行成功,如圖:然而,當(dāng)在MySQL 表格中復(fù)查的時候,發(fā)現(xiàn)數(shù)據(jù)庫表格為空值(如圖)要導(dǎo)入的excel 表格截圖如下:(好遺憾,似乎慕課網(wǎng)不能添加excel作為附件)仿寫代碼如下:高手們知道問題出在那里么?import?xlrd import?pymysql import?xlrd #?打開excel---------------------------------------------------------- def?open_excel(): ????try: ????????book?=?xlrd.open_workbook('C:/Users/lenovo/Desktop/工作紀(jì)錄就靠它了.xlsx')??#文件名,把文件與py文件放在同一目錄下 ????except: ????????print("open?excel?file?failed!") ????try: ????????sheet?=?book.sheet_by_name('ANZ紀(jì)錄')???#execl里面的worksheet1 ????????return?sheet ????except: ????????print("locate?worksheet?in?excel?failed!") #?驗證:open_excel?是跑的通的 #----------------------------------------------------------------- #連接數(shù)據(jù)庫------------------------------------------------------- try: ????db?=?pymysql.connect(host='localhost',user="root", ????????passwd='QAZwsx12345678', ????????db='test', ????????charset='utf8') except: ????print("could?not?connect?to?mysql?server") #?驗證:本機數(shù)據(jù)庫連接?是跑的通的 #---------------------------------------------------------------- def?search_count(): ????cursor?=?db.cursor() ????select?=?"select?count(PN)?from?pn_infor"?#獲取表中xxxxx記錄數(shù) ????cursor.execute(select)?#執(zhí)行sql語句 ????line_count?=?cursor.fetchone() ????print(line_count[0]) #驗證:search_count?是可以跑通的 #----------------------------------------------------------------- def?insert_deta(): ????sheet?=?open_excel() ????cursor?=?db.cursor() ????for?i?in?range(5,?sheet.nrows):?#前5行是標(biāo)題名,對應(yīng)表中的字段名所以應(yīng)該從第6行開始,計算機以0開始計數(shù),所以值是6 ????????inidate?=?sheet.cell(i,0).value?#取第i行第0列 ????????initiation_date?=?xlrd.xldate_as_datetime(inidate,0)?#?把數(shù)字型的日期解碼成真正的日期 ????????requestor?=?sheet.cell(i,1).value#取第i行第1列,下面依次類推 ????????EB??=?sheet.cell(i,2).value ????????EOL_By?=?xlrd.xldate_as_datetime(EB,0)?#?把數(shù)字型的日期解碼成真正的日期 ????????customer_name?=?sheet.cell(i,3).value ????????Type_of_Service?=?sheet.cell(i,4).value ????????PN?=?sheet.cell(i,5).value ????????description30?=?sheet.cell(i,6).value ????????description80?=?sheet.cell(i,7).value ????????Enable?=?sheet.cell(i,8).value ????????CostUSD?=?sheet.cell(i,9).value ????????CostAUD?=?sheet.cell(i,10).value ????????ListpriceAUD?=?sheet.cell(i,11).value ????????DistipriceAUD?=?sheet.cell(i,12).value ????????print(initiation_date) ????????print(requestor) ????????print(EOL_By) ????????print(customer_name) ????????print(Type_of_Service) ????????print(PN) ????????print(description30) ????????print(description80) ????????print(Enable) ????????print(CostUSD) ????????print(CostAUD) ????????print(ListpriceAUD) ????????print(DistipriceAUD) ????????print("---------------") ????????value?=?(initiation_date,requestor,EOL_By,customer_name,Type_of_Service,PN,description30,description80,Enable,CostUSD,CostAUD,ListpriceAUD,DistipriceAUD) ????????print(value) ????????sql?=?"INSERT?INTO?pn_infor(initiation_date,requestor,EOL_By,customer_name,Type_of_Service,PN,description30,description80,Enable,CostUSD,CostAUD,ListpriceAUD,DistipriceAUD)VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" ????????cursor.execute(sql,value)?#執(zhí)行sql語句 ????????db.commit() ????cursor.close()?#關(guān)閉連接 insert_deta() db.close()#關(guān)閉數(shù)據(jù) print?("ok?")
查看完整描述

3 回答

  • 3 回答
  • 0 關(guān)注
  • 1070 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號