视频功能演示
https://githubs.xyz/show/957bb6b1-7658-4d9a-9ee7-35db3c1dfd5e.mp4
背景痛点
前阵子xx公司有一批excel 需要去调整样式: 设置页面为A4,纵向。 标题设置字体颜色。
![image]()
但是,问题来了,excel有上千份,如果每一份都要手动打开调整,需要花费猴年马月的时间!
这里我有一个解决方案:可以指定一个excel格式模板,然后让一批excel都应用这个格式模板。也就是说上千份excel将一键完成格式调整。不会影响到源数据。
功能用法介绍
关注公众号“老罗软件”,回复:“小鱼办公” , 查看软件。
关注公众号“老罗软件”,回复:“小鱼办公” , 查看软件。
功能概述
专门批量调整一批excel的格式,不会影响到excel的源数据内容。指定一个excel格式模板,然后点击开始,即可完成一键调整。
首先我们需要选择要调整格式的excel目录,支持拖拽:
![image]()
然后点击新增格式, 输入一个名称,还有指定模板文件:
![image]()
这个名称是为了下次进来不用继续设置,直接应用这个名称的格式就可以了。
然后点击开始设置格式,就会自动执行,结果文件在excel目录的out下面:
![image]()
如果您有疑问可以一起来探讨,功能就介绍到 这里 ,希望能帮助大家,感谢!!!
如果您有疑问可以一起来探讨,功能就介绍到 这里 ,希望能帮助大家,感谢!!!
技术实现原理
软件是基于Python开发的现代化办公自动化软件,主要使用了如下技术架构:
1. PySide6 (Qt6) - 现代化GUI界面框架:
2. springboot: 格式的调整是通过后端java实现的。
3. 文件处理:os.walk() - 递归遍历目录结构。
部分代码解析
项目的 开始 按钮,会开启一个QThread线程去处理,首先是获取移除目录, 然后通过os.walk遍历目录获取到所有文件,然后一个一个进行处理,代码如下:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Excel格式设置服务类
提供Excel文件格式设置的核心功能
"""
import os
import json
from pathlib import Path
from typing import Dict, List, Any
from api.excel_api import ExcelAPI
from .user_config import get_format_by_name
from utils import FileUtils
from utils.logger import info, error, warning, debug
class ExcelSettingsService:
"""Excel格式设置服务类"""
def __init__(self):
"""初始化服务"""
self.excel_api = ExcelAPI()
def apply_format_to_excel(self, excel_file: str, format_name: str, output_file: str = None) -> bool:
"""将格式应用到Excel文件"""
format_settings = get_format_by_name(format_name)
# 调用API接口应用格式设置
self.excel_api.apply_excel_format(excel_file, format_settings, output_file)
def get_excel_files(self, directory: str) -> List[str]:
"""获取目录下的所有Excel文件"""
excel_files = []
try:
for root, dirs, files in os.walk(directory):
# 跳过out.error目录
if "out" in dirs:
dirs.remove("out")
if "error" in dirs:
dirs.remove("error")
for file in files:
if file.lower().endswith(('.xlsx', '.xls')):
excel_files.append(os.path.join(root, file))
except Exception as e:
error(f"扫描Excel文件失败: {str(e)}")
return excel_files
@staticmethod
def validate_directory(directory: str) -> bool:
"""验证目录是否有效"""
return os.path.exists(directory) and os.path.isdir(directory)
代码没有开源噢。如果您有疑问可以一起来探讨,今天就介绍到 这里 ,希望能帮助大家,感谢!!!