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

相关推荐
戴西软件4 分钟前
戴西CAxWorks.VPG车辆工程仿真软件技术解析(上)——安全仿真体系的自动化构建
运维·网络·数据库·人工智能·算法·安全·自动化
灯澜忆梦1 小时前
【MySQL10】进阶篇 | 索引_#1
数据库·sql·mysql
敲上瘾1 小时前
redis常用数据类型与操作方法
数据结构·数据库·redis·缓存
OceanWaves19931 小时前
mysql 5.7.29 主从同步配置
数据库·mysql·adb
molaoye1 小时前
win10下切换MySQL版本
数据库·mysql
丁引2 小时前
《数据清洗的艺术:如何用20行核心逻辑优雅地删除无标签图片》
前端·数据库·python
雨辰AI2 小时前
K8s 数据库 Secret 加密实战|密码明文漏洞彻底修复,等保密评双合规(金仓 / 达梦双库适配)
数据库·容器·kubernetes
XR1234567882 小时前
学校图书馆网络改造,方案谁更优?
网络·数据库·php
梦想的旅途22 小时前
企业微信自动化:自动发送文本、图片、文件
前端·数据库·microsoft
IvorySQL2 小时前
PostgreSQL 日报|复制槽泄漏修复(8 月 6 日)
数据库·postgresql