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进行转换。

相关推荐
薛定谔的算法10 小时前
phoneGPT:构建专业领域的检索增强型智能问答系统
前端·数据库·后端
Databend11 小时前
Databend 亮相 RustChinaConf 2025,分享基于 Rust 构建商业化数仓平台的探索
数据库
得物技术12 小时前
破解gh-ost变更导致MySQL表膨胀之谜|得物技术
数据库·后端·mysql
Raymond运维17 小时前
MariaDB源码编译安装(二)
运维·数据库·mariadb
沢田纲吉17 小时前
🗄️ MySQL 表操作全面指南
数据库·后端·mysql
RestCloud1 天前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud1 天前
为什么说零代码 ETL 是未来趋势?
数据库·api
ClouGence1 天前
CloudCanal + Paimon + SelectDB 从 0 到 1 构建实时湖仓
数据库
DemonAvenger2 天前
NoSQL与MySQL混合架构设计:从入门到实战的最佳实践
数据库·mysql·性能优化
AAA修煤气灶刘哥2 天前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql