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

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

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

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

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

3 回答

  • 3 回答
  • 0 關注
  • 1052 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號