# txt2xlsx **Repository Path**: hh688/txt2xlsx ## Basic Information - **Project Name**: txt2xlsx - **Description**: linux 系统将 txt 文件转换为 xlsx 文件,主要用于数据导出,解决时间日期字段识别不精准和格式转换问题,场景:mysql 数据导出并转换为xlsx,大数据量桌面工具导出失败等场景。 - **Primary Language**: Go - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-07-22 - **Last Updated**: 2025-12-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: txt, xlsx, 文件转换, txt转xlsx, csv转xlsx ## README # txt2xlsx txt 文本 转化成 xlsx 文档 # 限制 当前仅在centos7进行测试 # 安装 ``` # 下载可执行文件 wget https://gitee.com/hh688/txt2xlsx/releases/download/v_2.6.41/txt2xlsx_2.6.41.zip # 解压 unzip txt2xlsx_2.6.41.zip # 授权 chmod +x txt2xlsx # 移动到命令文件 mv txt2xlsx /usr/local/bin/ # 验证 [root@localhost tmp]# txt2xlsx -h NAME: txt2xlsx - txt 转换 xlsx USAGE: txt2xlsx [global options] command [command options] COMMANDS: help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --source-file value, -s value 源文件路径 --dest-file value, -d value 目标文件路径 --help, -h show help ``` # 使用 ``` txt2xlsx /your_path/test.txt /your_path/test.xlsx ``` # Linux配合脚本 ``` #!/bin/bash MySQL_user='your_user' MySQL_host='127.0.0.1' MySQL_password='your_password' MySQL_port=3306 MySQL_database='your_database' MySQL_output_file=/tmp MySQL_SqlInfo_file='/root/1_sql_info.txt' Sqlinfo=$(egrep -v '^\s*$|^\s*--' ${MySQL_SqlInfo_file}) Table_name=$(echo ${Sqlinfo} |sed -En 's/\s*select.*from\s+(`?[a-zA-Z0-9_]+`?\.)?`?([a-zA-Z0-9_]+)`?.*/\2/Ip') now_time=$(date '+%Y%m%d%H%M%S') mysql -u${MySQL_user} -p${MySQL_password} -h${MySQL_host} -P${MySQL_port} -e "use ${MySQL_database}; ${Sqlinfo}" > ${MySQL_output_file}/${now_time}_${Table_name}.txt if [[ $? -eq 0 ]];then echo "${Table_name} 表导出完成, 保存在 ${MySQL_output_file}/${now_time}_${Table_name}.xlsx " else echo "${Table_name} 表导出失败" fi txt2xlsx --source-file ${MySQL_output_file}/${now_time}_${Table_name}.txt --dest-file ${MySQL_output_file}/${now_time}_${Table_name}.xlsx ``` 将 txt2xlsx 命令放到"/usr/local/bin/"下。 再 root 目录下创建“/root/1_sql_info.txt”文件,将 SQL 写入该文件执行脚本即可。