2024年10月LightBlack工具(Excel工具箱)下载

发布时间:

  ⑴LightBlack工具是由以为论坛大佬制作的一个Excel工具箱软件,轻松实现Excel搜索查询,PDF转Word等功能,最大的特点就是软件是单文件程序,操作非常方便,内置的功能全部免费使用。特别适合经常需要进行PDF转换的用户使用。

  ⑵软件操作简单,先导入文件然后单击按钮就可以了(其实刚设定的时候连按钮都没,直接导入就自动转换了,后面想想,可能有些人不喜欢这种模式,所以改回了传统鼠标单击按钮,现在是可拖放也可导入,随便了,其他我做了限制,不是规定文件不能转换,比如Word转PDF,你导入PDF然后点击Word转PDF就不行,没办法不设置,到时候又软件有bug,转换完,会在左下角提示转换成功和文件路径的。

  ⑶from win.client import constants, gencache

  ⑷from PyQt.QtGui import *

  ⑸from PyQt.QtWidgets import *

  ⑹from PyQt.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 =

  ⒃self.filename = “”

  ⒄super(Main_Win,self.__init__(

  ⒅self.setAeptDrops(True

  ⒆self.Main_WinUI(

  ⒇def Main_WinUI(self:

  ⒈self.setWindowTitle(‘Excel查询系统’

  ⒉self.resize(,

  ⒊screen = QDesktopWidget(.screenGeometry(

  ⒋size = self.geometry(

  ⒌newLeft = (screen.width( - size.width( //

  ⒍newTop = (screen.height( - size.height( //

  ⒎self.move(newLeft, newTop

  ⒏self.setFixedSize(,

  ⒐palette = QPalette(

  ⒑pix = QPixmap(“D:\BaidudiskDownload\d\d\pythonandpycharm\QT_new\images\six.png”

  ⒒pix = pix.scaled(,

  ⒓palette.setBrush(QPalette.Background, QBrush(pix

  ⒔self.setPalette(palette

  ⒕self.setToolTip(‘温馨提示:如果不会使用请先阅读使用方法!’

  ⒖QToolTip.setFont(QFont(‘Times’,,QFont.Black

  ⒗#self.setWindowOpacity(.

  ⒘#self.setAttribute(Qt.WA_TranslucentBackground

  ⒙self.setWindowIcon(QIcon(os.getcwd(+‘\images\Book.ico’

  ⒚self.setWindowIcon(QIcon(‘D:\BaidudiskDownload\d\d\pythonandpycharm\QT_new\images\favicon.ico’

  ⒛self.Main_WinLayout(

  ①self.show(

  ②def Main_WinLayout(self:

  ③self.group = QGroupBox(self

  ④self.group.setTitle(‘参数设置区’

  ⑤self.group.setGeometry(,,,

  ⑥self.layout = QGridLayout(

  ⑦self.label_one = QLabel(‘《font color=#DB》请输入要搜索的关键词:《\font》’

  ⑧self.layout.addWidget(self.label_one,,

  ⑨self.edit_one = QLineEdit(

  ⑩self.edit_one.setAlignment(Qt.AlignCenter

  Ⅰself.edit_one.setPlaceholderText(‘这里输入要搜索的关键词’

  Ⅱself.layout.addWidget(self.edit_one,,

  Ⅲself.button_one = QPushButton(‘开始搜索’

  Ⅳself.layout.addWidget(self.button_one,,

  Ⅴself.button_one.clicked.connect(self.dialoginfo

  Ⅵself.button_two = QPushButton(‘导入文件’

  Ⅶself.layout.addWidget(self.button_two, ,

  Ⅷself.button_two.clicked.connect(self.groove_five

  Ⅸself.button_four = QPushButton(‘PDF转图片’

  Ⅹself.layout.addWidget(self.button_four, ,

  ㈠self.button_four.clicked.connect(self.Start_PDF_Image

  ㈡self.button_five = QPushButton(‘Word转PDF’

  ㈢self.layout.addWidget(self.button_five, ,

  ㈣self.button_five.clicked.connect(self.Start_Word_PDF

  ㈤# ---------------------------------------------------------------

  ㈥self.group_two = QGroupBox(self

  ㈦self.group_two.setTitle(‘输出日志’

  ㈧self.group_two.setGeometry(, , ,

  ㈨self.textedit_one = QTextEdit(

  ㈩self.textedit_one.setHtml(‘《font color=red》温馨提示!《\font》’##FAA

  self.textedit_one.setFont(QFont(“Times”,

  self.textedit_one.moveCursor(QTextCursor.End

  self.textedit_one.insertPlainText(“

  目前软件只支持Excel,Word,PDF文件

  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(‘订单数据’

  self.group_three.setGeometry(, , ,

  self.table_one = QTableWidget(

  # self.table_one.setColumnWidth(, #设置单元格的宽度

  # self.table_one.setColumnWidth(,

  # self.table_one.setColumnWidth(,

  # self.table_one.setColumnWidth(,

  # self.table_one.setColumnWidth(,

  self.setContextMenuPolicy(Qt.CustomContextMenu

  self.customContextMenuRequested.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.pile_True(self.table_one

  self.CP = self.contextMenu.addAction(‘关闭表格可编辑’

  self.CP.triggered.connect(lambda: self.pile_False(self.table_one

  self.CP = self.contextMenu.addAction(‘添加数据’

  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, ‘温馨提示!’, ‘大哥,你关键字,怎么也输点吧!’, QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes

  if reply == QMessageBox.Yes:

  self.dialoginfo(

  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“

  查询成功!!一共{len(find_str}条数据!!

  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

  self.textedit_one.moveCursor(QTextCursor.End

  self.textedit_one.insertPlainText(f“

  查询失败,找不到该条信息!!!

  reply = QMessageBox.question(win, ‘温馨提示!’, ‘请先导入文件在查询!!’, QMessageBox.Yes | QMessageBox.No , (QMessageBox.Yes

  if reply == QMessageBox.Yes:

  self.dialoginfo(

  def selected_tb_text(self,table_view:

  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

  indexes_dict[row] = [column]

  print(indexes_dict

  print(row,column

  text = []

  for row, columns in indexes_dict.items(:

  row_data = []

  for column in columns:

  data = table_view.item(row, column.text(

  except BaseException as e:

  data = ‘ ’

  finally:

  if row_data:

  row_data = ‘ ’ + data

  row_data = data

  if text:

  if len(text % == :

  text.append(‘

  ’

  text.append(row_data

  text.append(row_data

  print(text

  text_two = ‘’

  for item in text:

  text_two += item

  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(“

  正在导入Excel文件。..。..。..。..。.

  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[-:] == “xlsx” or self.filename[-:] == “xls”:

  self.textedit_one.moveCursor(QTextCursor.End

  self.textedit_one.insertPlainText(“

  self.textedit_one.moveCursor(QTextCursor.End

  self.textedit_one.insertPlainText(f‘

  成功导入Excel文件!,路径为:{self.filename}

  ’

  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 - ,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}条数据!

  ’

  self.table_one.setEditTriggers(QAbstractItemView.NoEditTriggers # 设置单元格不可编辑

  elif self.filename[-:] == “docx”:

  self.textedit_one.moveCursor(QTextCursor.End

  self.textedit_one.insertPlainText(“

  self.textedit_one.moveCursor(QTextCursor.End

  self.textedit_one.insertPlainText(f‘

  成功导入Word文件!,路径为:{self.filename}

  ’

  elif self.filename[-:] == “pdf”:

  self.textedit_one.moveCursor(QTextCursor.End

  self.textedit_one.insertPlainText(“

  self.textedit_one.moveCursor(QTextCursor.End

  self.textedit_one.insertPlainText(f‘

  成功导入PDF文件!,路径为:{self.filename}

  ’

  self.textedit_one.moveCursor(QTextCursor.End

  self.textedit_one.insertPlainText(“

  导入失败,请检查是否导入的是后缀为:xlsx,docx,pdf的文件!

  def Queryinfomation(self:

  for i in range(self.shape[]:

  for i in range(self.shape[]:

  Query = self.table_one.item(i,i.text(

  print(Query

  def pile_True(self,table_view:

  self.table_one.setEditTriggers(QAbstractItemView.DoubleClicked

  def pile_False(self,table_view:

  self.table_one.setEditTriggers(QAbstractItemView.NoEditTriggers

  def appendinfo(self,table_view:

  self.i +=

  self.table_one.setRowCount(self.i

  def dragEnterEvent(self, QDragEnterEvent:

  if QDragEnterEvent.mimeData(.hasText(:

  QDragEnterEvent.aeptProposedAction(

  def dropEvent(self, QDropEvent:

  self.filename = QDropEvent.mimeData(.text(.replace(‘ ‘’

  print(self.filename

  self.excal(

  def closeEvent(self, event:

  reply=QMessageBox.question(self,‘Message’,‘确定要退出吗?’,QMessageBox.Yes,QMessageBox.No

  if reply == QMessageBox.Yes:

  sys.exit(

  event.ignore(

  def pyMuPDF_fitz(self,pdfPath, imagePath:

  pdfDoc = fitz.open(pdfPath

  for pg in range(pdfDoc.pageCount:

  page = pdfDoc[pg]

  rotate = int(

  zoom_x = .

  zoom_y = .

  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[-:] == “docx” or self.filename[-:] == “dox”:

  reply = QMessageBox.question(win, ‘温馨提示!’, ‘程序开始执行时,因为计算量大可能会导致卡顿,这是正常现象,请不要乱点,请耐心稍等一会儿!!!’, QMessageBox.Yes | QMessageBox.No,(QMessageBox.Yes

  if reply == QMessageBox.Yes:

  self.Start_Word_PDF(

  Word_pdf_path = self.filename.replace(self.filename[-:],“pdf”

  word = gencache.EnsureDispatch(‘Word.Application’

  doc = word.Documents.Open(self.filename, ReadOnly=

  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“

  Word文件已成功转换PDF文件,请前往Word同目录下查看!!!

  生成路径为:{Word_pdf_path}

  QMessageBox.question(win, ‘温馨提示!’, ‘请检查是否为Word文件!!’,

  QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes

  def Start_PDF_Image(self:

  if self.filename[-:] == “pdf”:

  reply = QMessageBox.question(win, ‘温馨提示!’, ‘程序开始执行时,因为计算量大可能会导致卡顿,这是正常现象,请不要乱点,耐心稍等一会儿!!!’,QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes

  if reply == QMessageBox.Yes:

  self.Start_PDF_Image(

  self.textedit_one.moveCursor(QTextCursor.End

  self.textedit_one.insertPlainText(f‘

  正在转换PDF图片,

  ’

  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‘

  PDF文件已成功转换图片文件,请前往桌面查看!!!

  生成路径为:{PDF_images_path}

  ’

  QMessageBox.question(win, ‘温馨提示!’, ‘请检查是否为PDF文件!!’,

  QMessageBox.Yes | QMessageBox.No, (QMessageBox.Yes

  if __name__ == ‘__main__’:

  app = QApplication(sys.argv

  win = Main_Win(

  sys.exit(app.exec_(