有一个前提要求电脑要有Word,Excel,PDF,不然软件用不了,会闪退!
复制代码
from pdf2docx import Converter
from configparser import ConfigParser
import os
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from xlrd import *
import fitz
import os
import pandas as pd
import sys
import openpyxl
from win32com.client import constants, gencache
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('多功能系统')
self.resize(1700,880)
self.group.setLayout(self.layout)
def dialoginfo(self):
find_str = []
if self.filename:
if self.edit_one.text() == "":
reply=QMessageBox.question(win, '温馨提示!', '大哥,你关键字,怎么也输点吧!', 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)}条数据!!\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.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, '温馨提示!', '请先导入文件在查询!!', 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()
indexes_dict = {}
for index in indexes:
row, column = index.row(), index.column()
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)作者: xuanze 时间: 2022-5-20 16:19
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): # 重写键盘监听事件
# 监听 CTRL+C 组合键,实现复制数据到粘贴板
if (event.key() == Qt.Key_C) and QApplication.keyboardModifiers() == Qt.ControlModifier:
text = self.selected_tb_text(self.table_one)
def showMenu(self, pos):
print(pos)
self.contextMenu.exec_(QCursor.pos())
def groove_five(self):
self.textedit_one.moveCursor(QTextCursor.End)
self.textedit_one.insertPlainText("\n正在导入Excel文件..............\n")
self.filename,ok = QFileDialog.getOpenFileName(self,'想好了在选,记得选EXCAL文件!!!!','C:\\','文件类型默认所有,这个你不用担心:(*.*)')
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导入成功!\n")
self.textedit_one.moveCursor(QTextCursor.End)
self.textedit_one.insertPlainText(f'\n成功导入Excel文件!,路径为:{self.filename}\n')
self.data = pd.read_excel(self.filename)
print("123")
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)}条数据!\n')
self.table_one.setEditTriggers(QAbstractItemView.NoEditTriggers) # 设置单元格不可编辑
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)