波蘭vs墨西哥勝平負(fù)預(yù)測分析 ,由論壇大佬原創(chuàng)制作的一個(gè)Excel工具箱軟件,能實(shí)現(xiàn)Excel搜索查詢,PDF轉(zhuǎn)Word等功能,優(yōu)點(diǎn)是單文件程序,操作方面,無需多個(gè)軟件來回切換,全部功能,方便經(jīng)常需要轉(zhuǎn)換的朋友們操作體驗(yàn)。本次帶來LightBlack1.00首發(fā)版下載,有相關(guān)PDF工作轉(zhuǎn)換需求的朋友們可以下載使用。
新的軟件操作簡單,先導(dǎo)入文件然后單擊按鈕就可以了(其實(shí)剛設(shè)定的時(shí)候連按鈕都沒,直接導(dǎo)入就自動(dòng)轉(zhuǎn)換了,后面想想,可能有些人不喜歡這種模式,所以改回了傳統(tǒng)鼠標(biāo)單擊按鈕),現(xiàn)在是可拖放也可導(dǎo)入,隨便了,其他我做了限制,不是規(guī)定文件不能轉(zhuǎn)換,比如Word轉(zhuǎn)PDF,你導(dǎo)入PDF然后點(diǎn)擊Word轉(zhuǎn)PDF就不行,沒辦法不設(shè)置,到時(shí)候又軟件有bug,轉(zhuǎn)換完,會(huì)在左下角提示轉(zhuǎn)換成功和文件路徑的
from win32com.client import constants, gencache
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from xlrd import *
import pandas
import fitz
import os
import pandas as pd
import sys
?
class Main_Win(QWidget):
? ? def __init__(self):
? ? ? ? self.i = 0
? ? ? ? self.filename =
? ? ? ? super(Main_Win,self).__init__()
? ? ? ? self.setAcceptDrops(True)
? ? ? ? self.Main_WinUI()
? ? def Main_WinUI(self):
? ? ? ? self.setWindowTitle('Excel查詢系統(tǒng)')
? ? ? ? self.resize(1700,880)
?
? ? ? ? screen = QDesktopWidget().screenGeometry()
? ? ? ? size = self.geometry()
? ? ? ? newLeft = (screen.width() - size.width()) // 2
? ? ? ? newTop = (screen.height() - size.height()) // 2
? ? ? ? self.move(newLeft, newTop)
? ? ? ? self.setFixedSize(1700,880)
?
? ? ? ? palette = QPalette()
? ? ? ? pix = QPixmap(D:\\BaiduNetdiskDownload\\d\\d\\pythonandpycharm\\QT5_new\\images\\six.png)
? ? ? ? pix = pix.scaled(1300, 880)
? ? ? ? palette.setBrush(QPalette.Background, QBrush(pix))
? ? ? ? self.setPalette(palette)
?
? ? ? ? self.setToolTip('溫馨提示:如果不會(huì)使用請(qǐng)先閱讀使用方法!')
? ? ? ? QToolTip.setFont(QFont('Times',10,QFont.Black))
?
? ? ? ? #self.setWindowOpacity(0.8)
? ? ? ? #self.setAttribute(Qt.WA_TranslucentBackground)
?
? ? ? ? self.setWindowIcon(QIcon(os.getcwd()+'\\images\\Book.ico'))
? ? ? ? self.setWindowIcon(QIcon('D:\\BaiduNetdiskDownload\\d\\d\\pythonandpycharm\\QT5_new\\images\\favicon.ico'))
?
?
? ? ? ? self.Main_WinLayout()
? ? ? ? self.show()
? ? def Main_WinLayout(self):
?
? ? ? ? self.group = QGroupBox(self)
? ? ? ? self.group.setTitle('參數(shù)設(shè)置區(qū)')
? ? ? ? self.group.setGeometry(10,10,400,300)
? ? ? ? self.layout = QGridLayout()
?
? ? ? ? self.label_one = QLabel('請(qǐng)輸入要搜索的關(guān)鍵詞:<\\font>')
? ? ? ? self.layout.addWidget(self.label_one,0,0)
?
? ? ? ? self.edit_one = QLineEdit()
? ? ? ? self.edit_one.setAlignment(Qt.AlignCenter)
? ? ? ? self.edit_one.setPlaceholderText('這里輸入要搜索的關(guān)鍵詞')
? ? ? ? self.layout.addWidget(self.edit_one,0,1)
?
? ? ? ? self.button_one = QPushButton('開始搜索')
? ? ? ? self.layout.addWidget(self.button_one,1,0)
? ? ? ? self.button_one.clicked.connect(self.dialoginfo)
? ? ? ? self.button_two = QPushButton('導(dǎo)入文件')
? ? ? ? self.layout.addWidget(self.button_two, 1, 1)
? ? ? ? self.button_two.clicked.connect(self.groove_five)
?
? ? ? ? self.button_four = QPushButton('PDF轉(zhuǎn)圖片')
? ? ? ? self.layout.addWidget(self.button_four, 2, 0)
? ? ? ? self.button_four.clicked.connect(self.Start_PDF_Image)
? ? ? ? self.button_five = QPushButton('Word轉(zhuǎn)PDF')
? ? ? ? self.layout.addWidget(self.button_five, 2, 1)
? ? ? ? self.button_five.clicked.connect(self.Start_Word_PDF)
?
?
# ---------------------------------------------------------------
?
? ? ? ? self.group_two = QGroupBox(self)
? ? ? ? self.group_two.setTitle('輸出日志')
? ? ? ? self.group_two.setGeometry(10, 320, 400, 550)
? ? ? ? self.textedit_one = QTextEdit()
? ? ? ? self.textedit_one.setHtml('溫馨提示!<\\font>')##00FA9A
? ? ? ? self.textedit_one.setFont(QFont(Times,11))
? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? self.textedit_one.insertPlainText(\n目前軟件只支持Excel,Word,PDF文件\n)
?
?
? ? ? ? self.layout_two = QGridLayout()
? ? ? ? self.textedit_one.setReadOnly(True)
? ? ? ? self.layout_two.addWidget(self.textedit_one)
? ? ? ? self.group_two.setLayout(self.layout_two)
?
? ? ? ? self.group_three = QGroupBox(self)
? ? ? ? self.layout_two = QHBoxLayout()
? ? ? ? self.group_three.setTitle('訂單數(shù)據(jù)')
? ? ? ? self.group_three.setGeometry(420, 10, 1265, 860)
? ? ? ? self.table_one = QTableWidget()
?
?
? ? ? ? # self.table_one.setColumnWidth(0, 200)#設(shè)置單元格的寬度
? ? ? ? # self.table_one.setColumnWidth(1, 200)
? ? ? ? # self.table_one.setColumnWidth(2, 200)
? ? ? ? # self.table_one.setColumnWidth(3, 200)
? ? ? ? # self.table_one.setColumnWidth(4, 200)
?
? ? ? ? self.setContextMenuPolicy(Qt.CustomContextMenu)
? ? ? ? self.customContextMenued.connect(self.showMenu)
? ? ? ? self.contextMenu = QMenu(self)
? ? ? ? self.CP = self.contextMenu.addAction('')
? ? ? ? self.CP.triggered.connect(lambda:self.selected_tb_text(self.table_one))
? ? ? ? self.CP = self.contextMenu.addAction('打開表格可編輯')
? ? ? ? self.CP.triggered.connect(lambda: self.compile_True(self.table_one))
? ? ? ? self.CP = self.contextMenu.addAction('關(guān)閉表格可編輯')
? ? ? ? self.CP.triggered.connect(lambda: self.compile_False(self.table_one))
? ? ? ? self.CP = self.contextMenu.addAction('添加數(shù)據(jù)')
? ? ? ? self.CP.triggered.connect(lambda: self.appendinfo(self.table_one))
?
?
? ? ? ? self.layout_two.addWidget(self.table_one)
? ? ? ? self.group_three.setLayout(self.layout_two)
? ? ? ? QApplication.processEvents()
?
? ? ? ? self.group.setLayout(self.layout)
? ? def dialoginfo(self):
? ? ? ? find_str = []
? ? ? ? if self.filename:
? ? ? ? ? ? if self.edit_one.text() == :
? ? ? ? ? ? ? ? reply=QMessageBox.question(win, '溫馨提示!', '大哥,你關(guān)鍵字,怎么也輸點(diǎn)吧!', QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes))
? ? ? ? ? ? ? ? if reply == QMessageBox.Yes:
? ? ? ? ? ? ? ? ? ? pass
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? self.dialoginfo()
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? for i in self.data.to_dict('records'):
? ? ? ? ? ? ? ? ? ? for value in i.values():
? ? ? ? ? ? ? ? ? ? ? ? if str(value) == str(self.edit_one.text()):
? ? ? ? ? ? ? ? ? ? ? ? ? ? find_str.append(i)
? ? ? ? ? ? ? ? print(find_str)
? ? ? ? ? ? ? ? if len(find_str):
? ? ? ? ? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? ? ? ? ? self.textedit_one.insertPlainText(f\n查詢成功?。∫还瞷len(find_str)}條數(shù)據(jù)?。n)
? ? ? ? ? ? ? ? ? ? self.table_one.setRowCount(len(find_str))
? ? ? ? ? ? ? ? ? ? self.table_one.clearContents()
? ? ? ? ? ? ? ? ? ? for s in range(len(find_str)):
? ? ? ? ? ? ? ? ? ? ? ? for key,value in find_str[s].items():
? ? ? ? ? ? ? ? ? ? ? ? ? ? item = QTableWidgetItem(str(value))
? ? ? ? ? ? ? ? ? ? ? ? ? ? item.setTextAlignment(Qt.AlignCenter)
? ? ? ? ? ? ? ? ? ? ? ? ? ? self.table_one.setItem(s, self.head_list.index(key), item)
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? ? ? ? ? self.textedit_one.insertPlainText(f\n查詢失敗,找不到該條信息?。?!\n)
? ? ? ? else:
? ? ? ? ? ? reply = QMessageBox.question(win, '溫馨提示!', '請(qǐng)先導(dǎo)入文件在查詢??!', QMessageBox.Yes | QMessageBox.No , (QMessageBox.Yes))
? ? ? ? ? ? if reply == QMessageBox.Yes:
? ? ? ? ? ? ? ? pass
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? self.dialoginfo()
? ? def selected_tb_text(self,table_view):
? ? ? ? try:
? ? ? ? ? ? indexes = table_view.selectedIndexes()? # 獲取表格對(duì)象中被選中的數(shù)據(jù)索引列表
? ? ? ? ? ? indexes_dict = {}
? ? ? ? ? ? for index in indexes:? # 遍歷每個(gè)單元格
? ? ? ? ? ? ? ? row, column = index.row(), index.column()? # 獲取單元格的行號(hào),列號(hào)
? ? ? ? ? ? ? ? if row in indexes_dict.keys():
? ? ? ? ? ? ? ? ? ? indexes_dict[row].append(column)
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? indexes_dict[row] = [column]
? ? ? ? ? ? print(indexes_dict)
? ? ? ? ? ? print(row,column)
? ? ? ? ? ? text = []
? ? ? ? ? ? for row, columns in indexes_dict.items():
? ? ? ? ? ? ? ? row_data = []
? ? ? ? ? ? ? ? for column in columns:
? ? ? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? ? ? data = table_view.item(row, column).text()
? ? ? ? ? ? ? ? ? ? except BaseException as e:
? ? ? ? ? ? ? ? ? ? ? ? data = ' '
? ? ? ? ? ? ? ? ? ? finally:
? ? ? ? ? ? ? ? ? ? ? ? if row_data:
? ? ? ? ? ? ? ? ? ? ? ? ? ? row_data = ' ' + data
? ? ? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? ? ? row_data = data
?
? ? ? ? ? ? ? ? ? ? ? ? if text:
? ? ? ? ? ? ? ? ? ? ? ? ? ? if len(text) % 4 == 0:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? text.append('\n')
? ? ? ? ? ? ? ? ? ? ? ? ? ? text.append(row_data)
? ? ? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? ? ? text.append(row_data)
? ? ? ? ? ? print(text)
? ? ? ? ? ? text_two = ''
? ? ? ? ? ? for item in text:
? ? ? ? ? ? ? ? text_two += item
? ? ? ? ? ? try:
? ? ? ? ? ? ? ? clipboard = QApplication.clipboard()
? ? ? ? ? ? ? ? clipboard.setText(text_two)? # 到粘貼板
? ? ? ? ? ? except BaseException as e:
? ? ? ? ? ? ? ? print(e)
? ? ? ? except BaseException as e:
? ? ? ? ? ? print(e)
? ? ? ? ? ? clipboard = QApplication.clipboard()
? ? ? ? ? ? clipboard.setText(text_two)
? ? ? ? ? ? return ''
? ? def keyPressEvent(self, event):? ? ?# 重寫鍵盤監(jiān)聽事件
? ? ? ? # 監(jiān)聽 CTRL+C 組合鍵,實(shí)現(xiàn)數(shù)據(jù)到粘貼板
? ? ? ? if (event.key() == Qt.Key_C) and QApplication.keyboardModifiers() == Qt.ControlModifier:
? ? ? ? ? ? text = self.selected_tb_text(self.table_one)? # 獲取當(dāng)前表格選中的數(shù)據(jù)
? ? def showMenu(self, pos):
? ? ? ? print(pos)
? ? ? ? self.contextMenu.exec_(QCursor.pos())? # 在鼠標(biāo)位置顯示
? ? def groove_five(self):
? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? self.textedit_one.insertPlainText(\n正在導(dǎo)入Excel文件..............\n)
? ? ? ? self.filename,ok = QFileDialog.getOpenFileName(self,'請(qǐng)選擇EXCAL文件?。。?!','C:\\','文件類型默認(rèn)所有,這個(gè)你不用擔(dān)心:(*.*)')
? ? ? ? self.excal()
? ? def excal(self):
? ? ? ? print(self.filename)
? ? ? ? self.head_list = []
? ? ? ? self.sum_list = []
? ? ? ? if self.filename[-4:] == xlsx or self.filename[-3:] == xls:
? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? self.textedit_one.insertPlainText(\n導(dǎo)入成功!\n)
? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? self.textedit_one.insertPlainText(f'\n成功導(dǎo)入Excel文件!,路徑為:{self.filename}\n')
?
? ? ? ? ? ? self.data = pd.read_excel(self.filename)
? ? ? ? ? ? for i in self.data:
? ? ? ? ? ? ? ? self.head_list.append(i)
? ? ? ? ? ? self.table_one.setRowCount(len(self.data[i].values))
? ? ? ? ? ? self.table_one.setColumnCount(len(self.head_list))
? ? ? ? ? ? self.table_one.setHorizontalHeaderLabels(self.head_list)
?
? ? ? ? ? ? for j in self.head_list:
? ? ? ? ? ? ? ? for k in self.data[j].values:
? ? ? ? ? ? ? ? ? ? s = QTableWidgetItem(str(k))
? ? ? ? ? ? ? ? ? ? s.setTextAlignment(Qt.AlignCenter)
? ? ? ? ? ? ? ? ? ? self.sum_list.append(k)
? ? ? ? ? ? ? ? ? ? self.table_one.setItem(len(self.sum_list) - 1,int(self.head_list.index(j)), s)
? ? ? ? ? ? ? ? self.sum_list.clear()
? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? self.textedit_one.insertPlainText(f'目前有{len(self.data[j].values)}條數(shù)據(jù)!\n')
? ? ? ? ? ? self.table_one.setEditTriggers(QAbstractItemView.NoEditTriggers)? # 設(shè)置單元格不可編輯
?
? ? ? ? elif self.filename[-4:] == docx:
? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? self.textedit_one.insertPlainText(\n導(dǎo)入成功!\n)
? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? self.textedit_one.insertPlainText(f'\n成功導(dǎo)入Word文件!,路徑為:{self.filename}\n')
? ? ? ? elif self.filename[-3:] == pdf:
? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? self.textedit_one.insertPlainText(\n導(dǎo)入成功!\n)
? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? self.textedit_one.insertPlainText(f'\n成功導(dǎo)入PDF文件!,路徑為:{self.filename}\n')
?
? ? ? ? else:
? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? self.textedit_one.insertPlainText(\n導(dǎo)入失敗,請(qǐng)檢查是否導(dǎo)入的是后綴為:xlsx,docx,pdf的文件!\n)
?
? ? def Queryinfomation(self):
? ? ? ? for i in range(self.shape[0]):
? ? ? ? ? ? for i2 in range(self.shape[1]):
? ? ? ? ? ? ? ? Query = self.table_one.item(i,i2).text()
? ? ? ? ? ? ? ? print(Query)
? ? def compile_True(self,table_view):
? ? ? ? self.table_one.setEditTriggers(QAbstractItemView.DoubleClicked)
? ? def compile_False(self,table_view):
? ? ? ? self.table_one.setEditTriggers(QAbstractItemView.NoEditTriggers)
? ? def appendinfo(self,table_view):
? ? ? ? self.i +=1
? ? ? ? self.table_one.setRowCount(self.i)
?
? ? def dragEnterEvent(self, QDragEnterEvent):
? ? ? ? if QDragEnterEvent.mimeData().hasText():
? ? ? ? ? ? QDragEnterEvent.acceptProposedAction()
? ? def dropEvent(self, QDropEvent):
? ? ? ? self.filename = QDropEvent.mimeData().text().replace('file:///', '')
? ? ? ? print(self.filename)
? ? ? ? self.excal()
? ? def closeEvent(self, event):
? ? ? ? reply=QMessageBox.question(self,'Message','確定要退出嗎?',QMessageBox.Yes,QMessageBox.No)
? ? ? ? if reply == QMessageBox.Yes:
? ? ? ? ? ? sys.exit()
? ? ? ? else:
? ? ? ? ? ? event.ignore()
? ? def pyMuPDF_fitz(self,pdfPath, imagePath):
? ? ? ? pdfDoc = fitz.open(pdfPath)
? ? ? ? for pg in range(pdfDoc.pageCount):
? ? ? ? ? ? page = pdfDoc[pg]
? ? ? ? ? ? rotate = int(0)
? ? ? ? ? ? zoom_x = 1.33333333
? ? ? ? ? ? zoom_y = 1.33333333
? ? ? ? ? ? mat = fitz.Matrix(zoom_x, zoom_y).preRotate(rotate)
? ? ? ? ? ? pix = page.getPixmap(matrix=mat, alpha=False)
?
? ? ? ? ? ? if not os.path.exists(imagePath):
? ? ? ? ? ? ? ? os.makedirs(imagePath)
? ? ? ? ? ? pix.writePNG(imagePath + '/' + 'images_%s.png' % pg)
? ? def Start_Word_PDF(self):
? ? ? ? if self.filename[-4:] == docx or self.filename[-3:] == dox:
? ? ? ? ? ? reply = QMessageBox.question(win, '溫馨提示!', '程序開始執(zhí)行時(shí),因?yàn)橛?jì)算量大可能會(huì)導(dǎo)致卡頓,這是正常現(xiàn)象,請(qǐng)不要亂點(diǎn),請(qǐng)耐心稍等一會(huì)兒!??!', QMessageBox.Yes | QMessageBox.No,(QMessageBox.Yes))
? ? ? ? ? ? if reply == QMessageBox.Yes:
? ? ? ? ? ? ? ? pass
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? self.Start_Word_PDF()
?
? ? ? ? ? ? Word_pdf_path = self.filename.replace(self.filename[-4:],pdf)
? ? ? ? ? ? word = gencache.EnsureDispatch('Word.Application')
? ? ? ? ? ? doc = word.Documents.Open(self.filename, ReadOnly=1)
? ? ? ? ? ? doc.ExportAsFixedFormat(Word_pdf_path,constants.wdExportFormatPDF,Item=constants.wdExportDocumentWithMarkup,CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
? ? ? ? ? ? word.Quit(constants.wdDoNotSaveChanges)
? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? self.textedit_one.insertPlainText(f\nWord文件已成功轉(zhuǎn)換PDF文件,請(qǐng)前往Word同目錄下查看?。?!\n\n生成路徑為:{Word_pdf_path}\n)
? ? ? ? else:
? ? ? ? ? ? QMessageBox.question(win, '溫馨提示!', '請(qǐng)檢查是否為Word文件!!',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes))
?
? ? def Start_PDF_Image(self):
? ? ? ? if self.filename[-4:] == pdf:
? ? ? ? ? ? reply = QMessageBox.question(win, '溫馨提示!', '程序開始執(zhí)行時(shí),因?yàn)橛?jì)算量大可能會(huì)導(dǎo)致卡頓,這是正常現(xiàn)象,請(qǐng)不要亂點(diǎn),耐心稍等一會(huì)兒?。?!',QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes))
? ? ? ? ? ? if reply == QMessageBox.Yes:
? ? ? ? ? ? ? ? pass
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? self.Start_PDF_Image()
?
? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? self.textedit_one.insertPlainText(f'\n正在轉(zhuǎn)換PDF圖片,\n')
? ? ? ? ? ? PDF_images_path = os.path.join(os.path.expanduser(~), 'Desktop//PDF_images')
? ? ? ? ? ? self.pyMuPDF_fitz(self.filename, PDF_images_path)
? ? ? ? ? ? self.textedit_one.moveCursor(QTextCursor.End)
? ? ? ? ? ? self.textedit_one.insertPlainText(f'\nPDF文件已成功轉(zhuǎn)換圖片文件,請(qǐng)前往桌面查看?。?!\n\n生成路徑為:{PDF_images_path}\n')
?
? ? ? ? else:
? ? ? ? ? ? QMessageBox.question(win, '溫馨提示!', '請(qǐng)檢查是否為PDF文件!!',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes))
?
?
if __name__ == '__main__':
? ? app = QApplication(sys.argv)
? ? win = Main_Win()
? ? sys.exit(app.exec_())