亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于PyQt5實現(xiàn)SqlServer數(shù)據(jù)庫表導出Excel表格小工具

 更新時間:2023年12月03日 09:41:53   作者:Python 集中營  
這篇文章主要為大家詳細介紹了PyQt5的應(yīng)用案例之實現(xiàn)SqlServer數(shù)據(jù)庫表導出Excel表格小工具,文中的示例代碼講解詳細,需要的小伙伴可以參考一下

1、功能說明

windows桌面應(yīng)用,通過在應(yīng)用界面輸入SqlServer數(shù)據(jù)庫相關(guān)信息后一件導出excel表格數(shù)據(jù)。

應(yīng)用界面輸入信息如下:

數(shù)據(jù)庫IP:數(shù)據(jù)庫所在服務(wù)器的ip地址;

數(shù)據(jù)庫端口:數(shù)據(jù)庫服務(wù)的port端口;

數(shù)據(jù)庫名稱:需要連接的數(shù)據(jù)庫的名稱;

用戶名稱:需要連接的數(shù)據(jù)庫的用戶名稱;

密碼:需要連接的數(shù)據(jù)庫的密碼;

表名:需要導出的數(shù)據(jù)庫某張表的表名稱;

2、設(shè)計思路

界面應(yīng)用的UI設(shè)計通過python的PyQt5模塊開發(fā)窗口頁面功能,包括頁面布局槽函數(shù)關(guān)聯(lián)操作等。

數(shù)據(jù)庫連接以及數(shù)據(jù)操作使用的是python的三方非標準庫pymssql來完成數(shù)據(jù)庫層面的處理。

Excel表格數(shù)據(jù)處理使用的是常用的pandas模塊,可以快速的完成數(shù)據(jù)導出。

該工具使用的python模塊信息如下:

from PyQt5.QtWidgets import *

from PyQt5.QtGui import *

from PyQt5.QtCore import *

import sys

from datetime import datetime

import pymssql

import pandas as pd

import image

其中image模塊為打包后的圖片資源模塊,其他模塊均為python的標準或者非標準庫。

3、主要代碼塊

其中主要代碼塊為PyQt5應(yīng)用的UI界面以及槽函數(shù)的關(guān)聯(lián)和子線程模塊的調(diào)用等。

最后通過QThread子線程調(diào)用業(yè)務(wù)邏輯代碼塊,從而實現(xiàn)對數(shù)據(jù)庫以及Excel表格的處理。

主要代碼塊如下:

class DataBaseToExcelUI(QWidget):
    def __init__(self):
        super(DataBaseToExcelUI, self).__init__()
        self.init_ui()

    def init_ui(self):
        self.setWindowTitle('數(shù)據(jù)導出(SQLSERVER數(shù)據(jù)庫導出為Excel)')
        self.setWindowIcon(QIcon(':/analysis.ico'))
        self.resize(300, 400)

        self.database_ip_label = QLabel()
        self.database_ip_label.setText('數(shù)據(jù)庫IP:')

        self.database_ip_in = QLineEdit()
        self.database_ip_in.setText('192.168.10.10')

        self.database_port_label = QLabel()
        self.database_port_label.setText('數(shù)據(jù)庫端口:')

        self.database_port_in = QLineEdit()
        self.database_port_in.setText('1513')

        self.database_name_label = QLabel()
        self.database_name_label.setText('數(shù)據(jù)庫名稱:')

        self.database_name_in = QLineEdit()
        self.database_name_in.setText('source_data')

        self.database_user_label = QLabel()
        self.database_user_label.setText('數(shù)據(jù)庫用戶名:')

        self.database_user_in = QLineEdit()
        self.database_user_in.setText('sa')

        self.database_pwd_label = QLabel()
        self.database_pwd_label.setText('數(shù)據(jù)庫密碼:')

        self.database_pwd_in = QLineEdit()
        self.database_pwd_in.setText('')

        self.database_table_label = QLabel()
        self.database_table_label.setText('數(shù)據(jù)表名稱:')

        self.database_table_in = QLineEdit()
        self.database_table_in.setText('table_name')

        self.brower = QTextBrowser()
        self.brower.setReadOnly(True)
        self.brower.setFont(QFont('宋體', 8))
        self.brower.setPlaceholderText('日志處理過程區(qū)域...')
        self.brower.ensureCursorVisible()

        self.start_btn = QPushButton()
        self.start_btn.setText('開始導出')
        self.start_btn.clicked.connect(self.start_btn_clk)

        f_box = QFormLayout()
        f_box.addRow(self.database_ip_label, self.database_ip_in)
        f_box.addRow(self.database_port_label, self.database_port_in)
        f_box.addRow(self.database_name_label, self.database_name_in)
        f_box.addRow(self.database_user_label, self.database_user_in)
        f_box.addRow(self.database_pwd_label, self.database_pwd_in)
        f_box.addRow(self.database_table_label, self.database_table_in)
        f_box.addRow(self.start_btn)
        f_box.addRow(self.brower)

        self.thread_ = WorkThread(self)
        self.thread_.message.connect(self.show_message)
        self.thread_.finished.connect(self.finished)

        self.setLayout(f_box)

    def show_message(self, text):
        cursor = self.brower.textCursor()
        cursor.movePosition(QTextCursor.End)
        self.brower.append(text)
        self.brower.setTextCursor(cursor)
        self.brower.ensureCursorVisible()

    def finished(self, text):
        if text is True:
            self.start_btn.setEnabled(True)

    def start_btn_clk(self):
        self.start_btn.setEnabled(False)
        self.thread_.start()

以上代碼塊是應(yīng)用窗體相關(guān)的主要操作,供小伙伴們開發(fā)參考。

下面是關(guān)于QThread子線程的部分創(chuàng)建過程,可以將業(yè)務(wù)相關(guān)的處理放到子線程中執(zhí)行,這樣便不會導致UI頁面主線程出現(xiàn)阻塞等情況。

class WorkThread(QThread):
    message = pyqtSignal(str)
    finished = pyqtSignal(bool)

    def __init__(self, parent=None):
        super(WorkThread, self).__init__(parent)
        self.parent = parent
        self.working = True

    def __del__(self):
        self.working = False

到此這篇關(guān)于基于PyQt5實現(xiàn)SqlServer數(shù)據(jù)庫表導出Excel表格小工具的文章就介紹到這了,更多相關(guān)PyQt5數(shù)據(jù)庫導出Excel內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python數(shù)據(jù)分析Pandas?Dataframe排序操作

    Python數(shù)據(jù)分析Pandas?Dataframe排序操作

    這篇文章主要介紹了Python數(shù)據(jù)分析Pandas?Dataframe排序操作,數(shù)據(jù)的排序是比較常用的操作,DataFrame?的排序分為兩種,一種是對索引進行排序,另一種是對值進行排序,接下來就分別都介紹一下,需要的小伙伴可以參考一下
    2022-05-05
  • 在Python中pandas.DataFrame重置索引名稱的實例

    在Python中pandas.DataFrame重置索引名稱的實例

    今天小編就為大家分享一篇在Python中pandas.DataFrame重置索引名稱的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-11-11
  • Django利用Cookie實現(xiàn)反爬蟲的例子

    Django利用Cookie實現(xiàn)反爬蟲的例子

    這篇文章主要介紹了Django利用Cookie實現(xiàn)反爬蟲,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-04-04
  • Python?functools凍結(jié)參數(shù)小技巧實現(xiàn)代碼簡潔優(yōu)化

    Python?functools凍結(jié)參數(shù)小技巧實現(xiàn)代碼簡潔優(yōu)化

    這篇文章主要為大家介紹了Python?functools凍結(jié)參數(shù)小技巧實現(xiàn)代碼簡潔優(yōu)化示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-12-12
  • Python?Pyperclip模塊安裝和使用詳解

    Python?Pyperclip模塊安裝和使用詳解

    Pyperclip模塊兼容python2和python3,能跨平臺使用,這篇文章主要介紹了Pyperclip模塊安裝和使用詳解,需要的朋友可以參考下
    2023-03-03
  • 簡析Python的閉包和裝飾器

    簡析Python的閉包和裝飾器

    這篇文章主要為大家詳細介紹了Python的閉包和裝飾器,何為閉包?何為裝飾器?感興趣的小伙伴們可以參考一下
    2016-02-02
  • Python數(shù)據(jù)可視化:箱線圖多種庫畫法

    Python數(shù)據(jù)可視化:箱線圖多種庫畫法

    這篇文章主要介紹了Python數(shù)據(jù)可視化箱線圖多種庫畫法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-11-11
  • 基于python 字符編碼的理解

    基于python 字符編碼的理解

    下面小編就為大家?guī)硪黄趐ython 字符編碼的理解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • Python實現(xiàn)合并同一個文件夾下所有txt文件的方法示例

    Python實現(xiàn)合并同一個文件夾下所有txt文件的方法示例

    這篇文章主要介紹了Python實現(xiàn)合并同一個文件夾下所有txt文件的方法,涉及Python針對文件的遍歷、讀取、寫入等相關(guān)操作技巧,需要的朋友可以參考下
    2018-04-04
  • Python中的迭代器與生成器使用及說明

    Python中的迭代器與生成器使用及說明

    這篇文章主要介紹了Python中的迭代器與生成器使用及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12

最新評論