# office-builder **Repository Path**: gzcnkilys_admin/office-builder ## Basic Information - **Project Name**: office-builder - **Description**: No description available - **Primary Language**: Python - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-22 - **Last Updated**: 2025-03-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Office Builder Office Builder是一个用于生成Office文档的Python服务。它支持生成Word和PDF文档,提供了丰富的样式和内容配置选项。 ## 功能特点 - 支持生成Word和PDF文档 - 支持自定义文档样式(字体、颜色、对齐等) - 支持多种内容元素(标题、段落、列表、表格、图片、超链接等) - 支持文档模板 - 支持文档属性设置 - 支持中文字体 - RESTful API接口 ## 安装 1. 克隆项目: ```bash git clone https://github.com/yourusername/office-builder.git cd office-builder ``` 2. 创建虚拟环境: ```bash python -m venv venv source venv/bin/activate # Linux/Mac venv\Scripts\activate # Windows ``` 3. 安装依赖: ```bash pip install -r requirements.txt ``` ## 配置 1. 创建环境变量文件`.env`: ```env STORAGE_PATH=storage BASE_URL=http://localhost:8000 ``` 2. 创建字体目录: ```bash mkdir -p app/core/fonts ``` 3. 将中文字体文件复制到字体目录: - SimSun.ttf(宋体) - SimHei.ttf(黑体) ## 运行 ```bash python -m uvicorn app.main:create_app --reload ``` 服务将在 http://localhost:8000 启动。 ## API文档 访问 http://localhost:8000/docs 查看完整的API文档。 ### 生成文档 ```http POST /api/documents/generate Content-Type: application/json { "file_type": "word", "title": "文档标题", "content": [ { "type": "heading", "content": { "text": "一级标题", "level": 1, "style": { "font_size": 24, "bold": true } } }, { "type": "paragraph", "content": { "text": "这是一个段落", "style": { "font_size": 12, "paragraph_style": { "alignment": "justify" } } } } ], "style": { "default_font": "SimSun", "default_font_size": 12, "page_size": "A4", "page_margin": { "top": 1, "bottom": 1, "left": 1, "right": 1 } } } ``` ## 项目结构 ``` office-builder/ ├── app/ │ ├── core/ │ │ ├── fonts/ │ │ ├── word_generator.py │ │ ├── pdf_generator.py │ │ └── generator_factory.py │ ├── models/ │ │ └── document.py │ ├── services/ │ │ └── document_service.py │ ├── controllers/ │ │ └── document_controller.py │ └── main.py ├── storage/ │ ├── word/ │ └── pdf/ ├── requirements.txt └── README.md ``` ## 开发 1. 安装开发依赖: ```bash pip install -r requirements-dev.txt ``` 2. 运行测试: ```bash pytest ``` 3. 运行代码检查: ```bash flake8 black . ``` ## 贡献 1. Fork项目 2. 创建特性分支 3. 提交更改 4. 推送到分支 5. 创建Pull Request ## 许可证 MIT License