# 文档格式助手 **Repository Path**: knifecms/doc-format-agent ## Basic Information - **Project Name**: 文档格式助手 - **Description**: No description available - **Primary Language**: Python - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-05-17 - **Last Updated**: 2025-12-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: word格式, word样式 ## README # 智能Word样式复制器 基于Pandoc的交互式Word样式管理工具,能够智能抽取和复制Word文档的样式格式。 ## 🌟 主要功能 - **样式抽取**: 从Word文档中智能提取字体、颜色、段落等格式信息 - **样式应用**: 将抽取的样式应用到目标Word文档 - **批量处理**: 支持批量抽取和批量应用样式 - **智能备份**: 自动为修改的文档创建备份 - **结果汇报**: 生成详细的执行报告和样式分析 - **交互式界面**: 提供友好的命令行交互模式 ## 📋 系统要求 - Python 3.6+ - Pandoc (必须) - 依赖包: beautifulsoup4, lxml ## 🚀 快速开始 ### 1. 安装依赖 ```bash # 运行安装脚本 chmod +x install.sh ./install.sh # 或手动安装依赖 pip3 install beautifulsoup4 lxml # 安装Pandoc (Ubuntu/Debian) sudo apt-get install pandoc # 安装Pandoc (macOS) brew install pandoc # 安装Pandoc (Windows) # 下载并安装: https://pandoc.org/installing.html ``` ### 2. 基本使用 ```bash # 启动交互式模式 python3 word_style_copier.py --interactive # 抽取单个文档样式 python3 word_style_copier.py --extract source.docx # 应用样式到目标文档 python3 word_style_copier.py --apply input_docs/style_example.docx input_docs/target_example.docx # 批量应用样式 python3 word_style_copier.py --batch-apply source.docx target1.docx target2.docx ``` ## 📖 详细使用指南 ### 交互式模式 启动交互式模式享受完整的图形化操作体验: ```bash python3 word_style_copier.py --interactive ``` 交互式模式提供以下功能: - 🔄 单个/批量样式抽取 - 🎯 单个/批量样式应用 - 📊 样式分析查看 - 📋 执行报告生成 ### 命令行模式 #### 样式抽取 ```bash # 抽取文档样式并保存 python3 word_style_copier.py --extract document.docx # 指定输出文件 python3 word_style_copier.py --extract document.docx --output my_styles.json ``` #### 样式应用 ```bash # 应用样式到目标文档 python3 word_style_copier.py --apply source.docx target.docx python word_style_copier.py --apply input_docs/style_example.docx "D:/技术书籍/手把手教你开发Al Agent:零基础打造你的24小时智能助理/草稿/chapter_6_1_section1.docx" # 批量应用样式 python3 word_style_copier.py --batch-apply source.docx target1.docx target2.docx target3.docx # 生成报告 python3 word_style_copier.py --batch-apply source.docx target1.docx target2.docx --output report.md ``` #### 批量处理 ```bash # 批量抽取多个文档样式 python3 word_style_copier.py --batch-extract doc1.docx doc2.docx doc3.docx # 批量应用并生成详细报告 python3 word_style_copier.py --batch-apply template.docx report1.docx report2.docx --output batch_report.md ``` ## 📊 样式分析 工具会分析并提取以下样式信息: - **字体家族**: 文档中使用的所有字体 - **字体大小**: 不同层级的字体大小 - **颜色方案**: 文档中的颜色配置 - **CSS样式**: 内联样式和CSS规则 - **段落格式**: 标题、段落等格式信息 ## 🔧 工作流程 ### 样式抽取流程 1. 读取Word文档 (.docx) 2. 使用Pandoc转换为HTML格式 3. 解析HTML提取样式信息 4. 保存样式配置为JSON 5. 生成样式分析报告 ### 样式应用流程 1. 加载源文档样式配置 2. 备份目标文档 3. 使用Pandoc进行样式转换 4. 应用新样式到目标文档 5. 验证并生成结果报告 ## 📁 输出文件 ### 样式文件 (.json) 包含完整的样式配置信息: ```json { "font_families": ["宋体", "微软雅黑"], "font_sizes": ["12pt", "14pt", "16pt"], "colors": ["#000000", "#FF0000"], "css_styles": [...], "document_info": {...} } ``` ### 执行报告 (.md) 详细的执行结果和统计信息: - 处理文档数量 - 成功/失败统计 - 应用样式详情 - 备份文件位置 - 错误信息 ### 备份文件 为每个修改的文档创建时间戳备份: `document.docx.backup_20251025_160829` ## ⚠️ 注意事项 1. **Pandoc依赖**: 必须安装Pandoc,版本建议2.0+ 2. **文档格式**: 目前主要支持.docx格式 3. **样式兼容**: 复杂样式可能无法完全复制 4. **备份保护**: 修改文档前会自动创建备份 5. **权限要求**: 确保对目标文档有读写权限 ## 🔍 故障排除 ### 常见问题 **Q: 提示"Pandoc未找到"** A: 确保已安装Pandoc并添加到系统PATH中 **Q: 样式抽取失败** A: 检查文档格式是否为.docx,文件是否损坏 **Q: 应用样式后格式错乱** A: 检查源文档和目标文档的兼容性,已备份可恢复 **Q: 批量处理中断** A: 程序支持断点续传,已完成的文档不会重复处理 ### 日志查看 程序运行日志保存在 `word_style_copier.log` ## 📝 许可证 本工具由MiniMax Agent开发,仅供学习和研究使用。 ## 🤝 技术支持 如有问题或建议,请通过以下方式反馈: - 查看程序日志文件 - 检查Pandoc版本兼容性 - 确认文档格式和权限