前阵子xx公司有一批excel 需要转成PDF 文件, 且需要保持源样式:
但是,问题来了,excel有上千份,如果每一份都要手动打开进行转换,需要花费猴年马月的时间!
这里我有一个解决方案:可以指定excel目录, 然后进行批量一键转换即可。
专门进行批量转格式的工具,目前支持: xlsx转docx,xlsx转pdf,xlsx转png ,docx转xlsx,docx转pdf,docx转png。
首先我们需要选择要转换格式的目标文件目录,支持拖拽:
然后选择一个功能:
然后点击开始开始转换,就会自动执行,结果文件在excel目录的out下面:
如果您有疑问可以一起来探讨,功能就介绍到 这里 ,希望能帮助大家,感谢!!!
如果您有疑问可以一起来探讨,功能就介绍到 这里 ,希望能帮助大家,感谢!!!
软件是基于Python开发的现代化办公自动化软件,主要使用了如下技术架构:
1. PySide6 (Qt6) - 现代化GUI界面框架:
2. springboot: 格式的调整是通过后端java实现的。
3. 文件处理:os.walk() - 递归遍历目录结构。
项目的 开始 按钮,会开启一个QThread线程去处理,首先是获取移除目录, 然后通过os.walk遍历目录获取到所有文件,然后一个一个进行处理,代码如下:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
批量格式转换服务
提供Excel转PDF、Excel转图片、Excel转Word等格式转换功能
"""
import os
from api.excel_api import ExcelAPI
class FormatConvertService:
"""格式转换服务类"""
def __init__(self):
self.excel_api = ExcelAPI()
def get_excel_files(self, directory):
"""获取目录下的所有Excel文件"""
excel_files = []
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))
return excel_files
def get_word_files(self, directory):
"""获取目录下的所有Excel文件"""
excel_files = []
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(('.docx', '.doc')):
excel_files.append(os.path.join(root, file))
return excel_files
def convert_excel_to_pdf(self, excel_file, output_file):
"""将Excel转换为PDF"""
self.excel_api.excel_to_pdf(excel_file, output_file)
def convert_excel_to_image(self, excel_file, output_file):
"""将Excel转换为图片"""
self.excel_api.excel_to_png(excel_file, output_file)
def convert_excel_to_word(self, excel_file, output_file):
"""将Excel转换为Word"""
self.excel_api.excel_to_word(excel_file, output_file)
def convert_word_to_excel(self, excel_file, output_file):
self.excel_api.word_to_excel(excel_file, output_file)
def convert_word_to_pdf(self, excel_file, output_file):
self.excel_api.word_to_pdf(excel_file, output_file)
def convert_word_to_png(self, excel_file, output_file):
self.excel_api.word_to_png(excel_file, output_file)
代码没有开源噢。如果您有疑问可以一起来探讨,今天就介绍到 这里 ,希望能帮助大家,感谢!!!
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。