久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

python3怎么實現(xiàn)mysql導(dǎo)出excel-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)python3怎么實現(xiàn)mysql導(dǎo)出excel,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

成都創(chuàng)新互聯(lián)公司是專業(yè)的任城網(wǎng)站建設(shè)公司,任城接單;提供成都做網(wǎng)站、成都網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行任城網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!python的五大特點是什么

python的五大特點:1.簡單易學(xué),開發(fā)程序時,專注的是解決問題,而不是搞明白語言本身。2.面向?qū)ο?,與其他主要的語言如C++和Java相比, Python以一種非常強大又簡單的方式實現(xiàn)面向?qū)ο缶幊獭?.可移植性,Python程序無需修改就可以在各種平臺上運行。4.解釋性,Python語言寫的程序不需要編譯成二進制代碼,可以直接從源代碼運行程序。5.開源,Python是 FLOSS(自由/開放源碼軟件)之一。

Mysql中'employee'表內(nèi)容如下:

python3怎么實現(xiàn)mysql導(dǎo)出excel

# __Desc__ = 從數(shù)據(jù)庫中導(dǎo)出數(shù)據(jù)到excel數(shù)據(jù)表中
import xlwt
import pymysql
class MYSQL:
  def __init__(self):
    pass
  def __del__(self):
    self._cursor.close()
    self._connect.close()
  def connectDB(self):
    """
    連接數(shù)據(jù)庫
    :return:
    """
    try:
      self._connect = pymysql.Connect(
        host='localhost',
        port=3306,
        user='root',
        passwd='123456',
        db='test',
        charset='utf8'
      )
      return 0
    except:
      return -1
  def export(self, table_name, output_path):
    self._cursor = self._connect.cursor()
    count = self._cursor.execute('select * from '+table_name)
    # print(self._cursor.lastrowid)
    print(count)
    # 重置游標(biāo)的位置
    self._cursor.scroll(0, mode='absolute')
    # 搜取所有結(jié)果
    results = self._cursor.fetchall()
    # 獲取MYSQL里面的數(shù)據(jù)字段名稱
    fields = self._cursor.description
    workbook = xlwt.Workbook()
    # 注意: 在add_sheet時, 置參數(shù)cell_overwrite_ok=True, 可以覆蓋原單元格中數(shù)據(jù)。
    # cell_overwrite_ok默認(rèn)為False, 覆蓋的話, 會拋出異常.
    sheet = workbook.add_sheet('table_'+table_name, cell_overwrite_ok=True)
    # 寫上字段信息
    for field in range(0, len(fields)):
      sheet.write(0, field, fields[field][0])
    # 獲取并寫入數(shù)據(jù)段信息
    row = 1
    col = 0
    for row in range(1,len(results)+1):
      for col in range(0, len(fields)):
        sheet.write(row, col, u'%s' % results[row-1][col])
    workbook.save(output_path)
if __name__ == '__main__':
  mysql = MYSQL()
  flag = mysql.connectDB()
  if flag == -1:
    print('數(shù)據(jù)庫連接失敗')
  else:
    print('數(shù)據(jù)庫連接成功')
    mysql.export('employee', 'E:/test_input.xls')

執(zhí)行結(jié)果如下:

python3怎么實現(xiàn)mysql導(dǎo)出excel

關(guān)于“python3怎么實現(xiàn)mysql導(dǎo)出excel”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

名稱欄目:python3怎么實現(xiàn)mysql導(dǎo)出excel-創(chuàng)新互聯(lián)
分享地址:http://sd-ha.com/article24/cdhpje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作網(wǎng)站維護動態(tài)網(wǎng)站、定制開發(fā)、ChatGPT、網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)