- 帖子
- 4
- 积分
- 21
- 技术
- 0
- 捐助
- 0
- 注册时间
- 2022-5-20
|
2楼
发表于 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) # 设置单元格不可编辑
elif self.filename[-4:] == "docx":
self.textedit_one.moveCursor(QTextCursor.End)
self.textedit_one.insertPlainText("\n导入成功!\n")
self.textedit_one.moveCursor(QTextCursor.End)
self.textedit_one.insertPlainText(f'\n成功导入Word文件!,路径为:{self.filename}\n')
elif self.filename[-3:] == "pdf":
self.textedit_one.moveCursor(QTextCursor.End)
self.textedit_one.insertPlainText("\n导入成功!\n")
self.textedit_one.moveCursor(QTextCursor.End)
self.textedit_one.insertPlainText(f'\n成功导入PDF文件!,路径为:{self.filename}\n')
elif os.path.isdir(self.filename):
self.textedit_one.moveCursor(QTextCursor.End)
self.textedit_one.insertPlainText("\n导入成功!\n")
self.textedit_one.moveCursor(QTextCursor.End)
self.textedit_one.insertPlainText(f'\n成功导入内含PDF文件的文件夹!,路径为:{self.filename}\n')
else:
self.textedit_one.moveCursor(QTextCursor.End)
self.textedit_one.insertPlainText("\n导入失败,请检查是否导入的是后缀为: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, '温馨提示!', '程序开始执行时,因为计算量大可能会导致卡顿,这是正常现象,请不要乱点,请耐心稍等一会儿!!!', 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文件已成功转换PDF文件,请前往Word同目录下查看!!!\n\n生成路径为:{Word_pdf_path}\n")
else:
QMessageBox.question(win, '温馨提示!', '请检查是否为Word文件!!',
QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes))
def Start_PDF_Image(self):
if self.filename[-3:] == "pdf":
reply = QMessageBox.question(win, '温馨提示!', '程序开始执行时,因为计算量大可能会导致卡顿,这是正常现象,请不要乱点,耐心稍等一会儿!!!',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正在转换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文件已成功转换图片文件,请前往桌面查看!!!\n\n生成路径为:{PDF_images_path}\n')
else:
QMessageBox.question(win, '温馨提示!', '请检查是否为PDF文件!!',
QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes))
def Start_PDF_Word(self):
if os.path.isdir(self.filename):
QMessageBox.question(win, '温馨提示!', '程序开始执行时,因为计算量大可能会导致卡顿,这是正常现象,请不要乱点,耐心稍等一会儿!!!',
QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes))
config_parser = ConfigParser()
config_parser.read('config.cfg', encoding='utf-8')
config = config_parser['default']
for file in os.listdir(self.filename):
extension_name = os.path.splitext(file)[1]
if extension_name != '.pdf':
continue
file_name = os.path.splitext(file)[0]
pdf_file = self.filename + '/' + file
word_file = self.filename + '/' + file_name + '.docx'
cv = Converter(pdf_file)
cv.convert(word_file)
cv.close()
self.textedit_one.moveCursor(QTextCursor.End)
self.textedit_one.insertPlainText(f'\nPDF文件已成功转换图片文件,请前往桌面查看!!!\n\n生成路径为:{word_file}\n')
else:
QMessageBox.question(win, '温馨提示!', '请导入一个内含PDF文件的文件夹!!!',
QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes))
if __name__ == '__main__':
app = QApplication(sys.argv)
win = Main_Win()
sys.exit(app.exec_()) |
|