Document Generator Skill
Generate professional Word (.docx), Excel (.xlsx), and PDF documents with comprehensive formatting support including fonts, colors, tables, images, layouts, and more.
When to Use This Skill
Use this skill when the user needs to:
- - Create Word documents with rich formatting (headings, paragraphs, tables, images, styles)
- Generate Excel spreadsheets with formulas, styling, and data
- Export content to PDF format with professional layouts
- Work with document templates and fill them with data
- Create reports, invoices, data exports, or any formatted document output
Core Capabilities
Word Documents (.docx)
- - Text formatting: font family, size, color, bold, italic, underline
- Paragraph styles: alignment, spacing, indentation
- Tables with custom styling and borders
- Images with positioning and sizing
- Headers and footers
- Page layout: margins, orientation, page size
- Bullet and numbered lists
- Hyperlinks
Excel Spreadsheets (.xlsx)
- - Cell formatting: font, size, color, background
- Formulas and calculations
- Multiple sheets
- Column widths and row heights
- Cell borders and alignment
- Number formatting (currency, percentage, dates)
- Merged cells
- Freeze panes
PDF Documents (.pdf)
- - Text with custom fonts, sizes, and colors
- Paragraphs with alignment
- Tables with styling
- Images
- Page layout and margins
- Multi-page documents
- Headers and footers
How to Use
Step 1: Understand the Requirements
Ask clarifying questions if needed:
- - What type of document? (Word/Excel/PDF)
- What content should it contain?
- Any specific formatting requirements?
- Should it use a template?
- Where should the output be saved?
Step 2: Choose the Right Script
The skill provides three main scripts in the scripts/ directory:
- -
generate_word.py - For Word documents - INLINECODE2 - For Excel spreadsheets
- INLINECODE3 - For PDF documents
Each script accepts a JSON configuration that describes the document structure and content.
Step 3: Prepare the Configuration
Create a JSON configuration file that describes the document. The structure varies by document type - see the reference files for detailed schemas:
- -
references/word_schema.md - Word document configuration - INLINECODE5 - Excel spreadsheet configuration
- INLINECODE6 - PDF document configuration
Step 4: Generate the Document
Run the appropriate script with the configuration:
CODEBLOCK0
Step 5: Verify and Iterate
Check the generated document and make adjustments to the configuration if needed.
Working with Templates
All three document types support template-based generation:
- 1. Word Templates: Use existing .docx files and replace placeholders
- Excel Templates: Use existing .xlsx files and fill in data
- PDF Templates: Define reusable layouts in the configuration
To use a template, include a template field in your configuration pointing to the template file path.
Configuration Examples
Simple Word Document
CODEBLOCK1
Simple Excel Spreadsheet
CODEBLOCK2
Simple PDF Document
CODEBLOCK3
Best Practices
- 1. Start Simple: Begin with basic formatting and add complexity as needed
- Use Templates: For recurring document types, create templates to save time
- Validate Data: Check that data types match expected formats (numbers, dates, etc.)
- Test Incrementally: Generate documents frequently during development to catch issues early
- Handle Errors Gracefully: Provide clear error messages if configuration is invalid
Troubleshooting
Missing Dependencies: If scripts fail, ensure required Python packages are installed:
CODEBLOCK4
Font Issues: If custom fonts don't work, verify the font name is correct and available on the system.
Image Problems: Ensure image paths are absolute or relative to the script execution directory.
Excel Formulas: Use Excel formula syntax (e.g., =SUM(A1:A10)) as strings in the data array.
Advanced Features
For complex documents, refer to the detailed reference files:
- -
references/word_schema.md - Complete Word configuration options - INLINECODE10 - Complete Excel configuration options
- INLINECODE11 - Complete PDF configuration options
These references include examples of:
- - Complex table layouts
- Image positioning and sizing
- Advanced styling and themes
- Multi-page layouts
- Template variable substitution
- Conditional formatting
文档生成技能
生成专业的Word(.docx)、Excel(.xlsx)和PDF文档,支持全面的格式设置,包括字体、颜色、表格、图片、布局等。
何时使用此技能
当用户需要以下操作时使用此技能:
- - 创建带有丰富格式的Word文档(标题、段落、表格、图片、样式)
- 生成包含公式、样式和数据的Excel电子表格
- 将内容导出为具有专业布局的PDF格式
- 处理文档模板并用数据填充
- 创建报告、发票、数据导出或任何格式化的文档输出
核心功能
Word文档(.docx)
- - 文本格式:字体、字号、颜色、加粗、斜体、下划线
- 段落样式:对齐、间距、缩进
- 自定义样式和边框的表格
- 可定位和调整大小的图片
- 页眉和页脚
- 页面布局:边距、方向、纸张大小
- 项目符号和编号列表
- 超链接
Excel电子表格(.xlsx)
- - 单元格格式:字体、字号、颜色、背景
- 公式和计算
- 多个工作表
- 列宽和行高
- 单元格边框和对齐
- 数字格式(货币、百分比、日期)
- 合并单元格
- 冻结窗格
PDF文档(.pdf)
- - 自定义字体、字号和颜色的文本
- 带对齐的段落
- 带样式的表格
- 图片
- 页面布局和边距
- 多页文档
- 页眉和页脚
使用方法
步骤1:了解需求
如有需要,提出澄清性问题:
- - 需要什么类型的文档?(Word/Excel/PDF)
- 应包含什么内容?
- 是否有特定的格式要求?
- 是否使用模板?
- 输出文件应保存在哪里?
步骤2:选择合适的脚本
该技能在scripts/目录下提供三个主要脚本:
- - generateword.py - 用于Word文档
- generateexcel.py - 用于Excel电子表格
- generate_pdf.py - 用于PDF文档
每个脚本接受一个描述文档结构和内容的JSON配置。
步骤3:准备配置
创建一个描述文档的JSON配置文件。结构因文档类型而异——请参阅参考文件了解详细模式:
- - references/wordschema.md - Word文档配置
- references/excelschema.md - Excel电子表格配置
- references/pdf_schema.md - PDF文档配置
步骤4:生成文档
使用配置运行相应的脚本:
bash
python document-generator/scripts/generate_word.py config.json output.docx
python document-generator/scripts/generate_excel.py config.json output.xlsx
python document-generator/scripts/generate_pdf.py config.json output.pdf
步骤5:验证和迭代
检查生成的文档,如有需要对配置进行调整。
使用模板
所有三种文档类型都支持基于模板的生成:
- 1. Word模板:使用现有的.docx文件并替换占位符
- Excel模板:使用现有的.xlsx文件并填充数据
- PDF模板:在配置中定义可重复使用的布局
要使用模板,请在配置中包含指向模板文件路径的template字段。
配置示例
简单Word文档
json
{
page_setup: {
margins: {top: 1, bottom: 1, left: 1, right: 1}
},
content: [
{
type: heading,
text: 月度报告,
level: 1
},
{
type: paragraph,
text: 这是报告内容。,
font: {name: Arial, size: 11}
}
]
}
简单Excel电子表格
json
{
sheets: [
{
name: 销售数据,
data: [
[产品, 数量, 价格, 总计],
[小部件A, 10, 25.50, =B2*C2],
[小部件B, 5, 30.00, =B3*C3]
],
formatting: {
header_row: 0,
column_widths: [15, 10, 10, 10]
}
}
]
}
简单PDF文档
json
{
page_setup: {
size: A4,
margins: {top: 20, bottom: 20, left: 20, right: 20}
},
content: [
{
type: text,
text: 发票 #12345,
font: {name: Helvetica-Bold, size: 18}
},
{
type: paragraph,
text: 感谢您的惠顾。,
font: {name: Helvetica, size: 12}
}
]
}
最佳实践
- 1. 从简单开始:从基本格式开始,根据需要增加复杂度
- 使用模板:对于重复的文档类型,创建模板以节省时间
- 验证数据:检查数据类型是否与预期格式匹配(数字、日期等)
- 增量测试:在开发过程中频繁生成文档,及早发现问题
- 优雅处理错误:如果配置无效,提供清晰的错误信息
故障排除
缺少依赖:如果脚本运行失败,请确保安装了所需的Python包:
bash
pip install python-docx openpyxl reportlab Pillow
字体问题:如果自定义字体不起作用,请验证字体名称是否正确且系统可用。
图片问题:确保图片路径是绝对路径或相对于脚本执行目录的路径。
Excel公式:在数据数组中使用Excel公式语法(例如=SUM(A1:A10))作为字符串。
高级功能
对于复杂文档,请参阅详细的参考文件:
- - references/wordschema.md - 完整的Word配置选项
- references/excelschema.md - 完整的Excel配置选项
- references/pdf_schema.md - 完整的PDF配置选项
这些参考文件包含以下示例:
- - 复杂表格布局
- 图片定位和大小调整
- 高级样式和主题
- 多页布局
- 模板变量替换
- 条件格式