Python & PyQt5 实现 .his 文件批量转 Excel 工具

import os

from PyQt5.QtWidgets import QApplication, QFileDialog, QMessageBox

from his2excel import His2Excel

def convert_his_to_excel(his_files):

"""

将 .his 文件批量转换为 Excel 文件

:param his_files: 要转换的 .his 文件列表

"""

for his_file in his_files:

excel_file = os.path.splitext(his_file)[0] + '.xlsx'

if os.path.exists(excel_file):

QMessageBox.warning(None, "警告", f"文件已存在,跳过:{excel_file}")

continue

try:

His2Excel.convert(his_file, excel_file)

print(f"转换成功:{excel_file}")

except Exception as e:

QMessageBox.critical(None, "错误", f"转换失败:{e}")

def select_his_files():

"""

弹出文件选择对话框,选择 .his 文件

:return: 选择的 .his 文件列表

"""

his_files, _ = QFileDialog.getOpenFileNames(None, "选择 .his 文件", "", "HIS Files (*.his)")

return his_files

def main():

app = QApplication([])

his_files = select_his_files()

if his_files:

convert_his_to_excel(his_files)

else:

QMessageBox.information(None, "信息", "没有选择文件,程序将退出。")

if name == 'main':

main()

这段代码首先定义了一个convert_his_to_excel函数,用于将单个或多个.his文件转换为Excel文件。它使用了os.path.splitext来获取文件的基础名称,并添加.xlsx作为Excel文件的扩展名。如果目标Excel文件已存在,会弹出警告消息。如果转换过程中发生异常,会弹出错误消息。select_his_files函数用于弹出文件选择对话框,让用户选择.his文件。main函数则是程序的入口点,它启动Qt应用程序,调用select_his_files获取文件列表,并调用convert_his_to_excel进行转换。

相关推荐
weixin_3975740912 小时前
用自然语言查数据库出图表靠谱吗?一次智能问数实践复盘
数据库
字节跳动开源14 小时前
Viking AI 搜索 CLI 正式发布:会说话,就能做搜索推荐
数据库·人工智能·开源
TechWJ15 小时前
数据库在公司内网,出差路上想查数据怎么办?
服务器·数据库·mariadb
我是一颗柠檬15 小时前
【MySQL全面教学】MySQL事务与ACID Day9(2026年)
数据库·后端·mysql
橙子圆12315 小时前
Redis知识9之集群
数据库·redis·缓存
BlackHeart120316 小时前
【SQL】Oracle中序列(Sequence)作为默认值引发的ORA-00979
数据库·sql·oracle
bug菌16 小时前
【SpringBoot 3.x 第254节】夯爆了,数据库访问性能优化实战详解!
数据库·spring boot·后端
xxl大卡16 小时前
MySQL的执行流程
数据库·mysql
chicheese17 小时前
MySQL优化实践:选错JOIN 驱动表,性能相差几十倍
数据库·mysql
無限進步D17 小时前
MySQL 单行函数
数据库·mysql