DOCX Generation
Create and modify Word documents with advanced formatting, tables, images, and professional layouts.
Generate professional Word documents with rich formatting, dynamic content, and advanced layout features for automated document creation and template processing.
Features
- Rich text formatting with fonts, styles, and emphasis
- Advanced table creation with data binding
- Image insertion with positioning and wrapping
- Headers, footers, and page numbering
- Template processing with variable substitution
Connector Options
The node uses reusable connector configuration that applies to all document operations:
| Parameter | Type | Required | Description |
|---|---|---|---|
outputDirectory | TEXT | No | Default directory for generated documents |
templateDirectory | TEXT | No | Directory containing document templates |
defaultFont | TEXT | No | Default font family for documents (default: Calibri) |
defaultFontSize | INT | No | Default font size in points (default: 11) |
Methods
createDocument
Generate a new DOCX document with specified content and formatting.
| Parameter | Type | Required | Description |
|---|---|---|---|
fileName | TEXT | Yes | Name for the generated document |
content | Array | Yes | Document content structure |
formatting | Object | No | Global document formatting options |
metadata | Object | No | Document properties and metadata |
{
"fileName": "quarterly_report.docx",
"content": [
{
"type": "heading",
"level": 1,
"text": "Quarterly Business Report",
"style": "Title"
},
{
"type": "paragraph",
"text": "This report provides an overview of our Q3 performance and key achievements.",
"formatting": {
"alignment": "justify",
"spacing": {"after": 12}
}
},
{
"type": "table",
"headers": ["Metric", "Q2", "Q3", "Change"],
"rows": [
["Revenue", "$1.2M", "$1.5M", "+25%"],
["Customers", "150", "200", "+33%"]
]
}
],
"formatting": {
"pageSize": "A4",
"margins": {"top": 1, "bottom": 1, "left": 1.25, "right": 1.25},
"font": {"family": "Calibri", "size": 11}
},
"metadata": {
"title": "Q3 2024 Business Report",
"author": "Finance Team",
"subject": "Quarterly Performance"
}
}Output:
success(Boolean) - Document generation success statusfilePath(String) - Path to the generated documentpageCount(Number) - Number of pages in the documentwordCount(Number) - Total word countmetadata(Object) - Document properties and statistics
modifyDocument
Edit existing DOCX documents by adding, replacing, or removing content.
| Parameter | Type | Required | Description |
|---|---|---|---|
inputFile | TEXT | Yes | Path to the source document |
outputFile | TEXT | Yes | Path for the modified document |
operations | Array | Yes | List of modification operations |
preserveFormatting | BOOLEAN | No | Keep original formatting (default: true) |
{
"inputFile": "/sandbox/documents/template.docx",
"outputFile": "/sandbox/output/modified_report.docx",
"operations": [
{
"type": "replace",
"target": "{{COMPANY_NAME}}",
"replacement": "Acme Corporation"
},
{
"type": "insert",
"position": "end",
"content": {
"type": "paragraph",
"text": "This document was generated automatically."
}
},
{
"type": "updateTable",
"tableIndex": 0,
"newData": [
["Product A", "500", "$50,000"],
["Product B", "300", "$30,000"]
]
}
],
"preserveFormatting": true
}createFromTemplate
Generate documents using predefined templates with variable substitution.
| Parameter | Type | Required | Description |
|---|---|---|---|
templateFile | TEXT | Yes | Path to the template document |
outputFile | TEXT | Yes | Path for the generated document |
variables | Object | Yes | Variables for template substitution |
conditionalContent | Object | No | Rules for conditional content inclusion |
{
"templateFile": "/sandbox/templates/invoice_template.docx",
"outputFile": "/sandbox/invoices/invoice_001.docx",
"variables": {
"client_name": "ABC Company",
"invoice_number": "INV-2024-001",
"invoice_date": "2024-03-15",
"due_date": "2024-04-15",
"total_amount": "$5,000.00",
"line_items": [
{"description": "Consulting Services", "hours": 40, "rate": 100, "amount": 4000},
{"description": "Travel Expenses", "hours": 1, "rate": 1000, "amount": 1000}
]
},
"conditionalContent": {
"show_discount": false,
"include_notes": true,
"payment_terms": "net_30"
}
}Content Types
Text Content
| Content Type | Description | Parameters |
|---|---|---|
heading | Document headings with styles | level, text, style, numbering |
paragraph | Text paragraphs with formatting | text, alignment, spacing, indentation |
list | Bulleted or numbered lists | items, type, style, level |
text | Inline text with styling | text, bold, italic, underline, color |
Table Content
{
"type": "table",
"headers": ["Column 1", "Column 2", "Column 3"],
"rows": [
["Data 1", "Data 2", "Data 3"],
["Data 4", "Data 5", "Data 6"]
],
"formatting": {
"style": "TableGrid",
"headerStyle": {
"backgroundColor": "#4472C4",
"fontColor": "white",
"bold": true
},
"alternatingRows": true,
"borders": true,
"columnWidths": [2, 3, 2]
}
}Image Content
{
"type": "image",
"source": "/sandbox/images/chart.png",
"positioning": {
"width": 400,
"height": 300,
"alignment": "center",
"wrap": "square",
"margins": {"top": 6, "bottom": 6}
},
"caption": {
"text": "Figure 1: Sales Performance Chart",
"style": "Caption"
}
}Page Elements
{
"type": "pageBreak",
"breakType": "page"
}{
"type": "section",
"properties": {
"orientation": "landscape",
"margins": {"top": 0.5, "bottom": 0.5, "left": 0.5, "right": 0.5}
}
}Formatting Options
Font and Text Formatting
{
"textFormatting": {
"font": {
"family": "Arial",
"size": 12,
"color": "#000000",
"bold": false,
"italic": false,
"underline": false,
"strikethrough": false
},
"paragraph": {
"alignment": "left",
"spacing": {
"before": 0,
"after": 6,
"line": 1.15
},
"indentation": {
"left": 0,
"right": 0,
"firstLine": 0
}
}
}
}Page Layout
{
"pageLayout": {
"size": "A4",
"orientation": "portrait",
"margins": {
"top": 1,
"bottom": 1,
"left": 1.25,
"right": 1.25,
"header": 0.5,
"footer": 0.5
},
"columns": {
"count": 1,
"spacing": 0.5,
"separator": false
}
}
}Headers and Footers
{
"headers": {
"default": {
"content": [
{
"type": "paragraph",
"text": "Quarterly Report - Q3 2024",
"alignment": "center"
}
]
},
"firstPage": {
"content": []
}
},
"footers": {
"default": {
"content": [
{
"type": "paragraph",
"text": "Page {{PAGE_NUMBER}} of {{TOTAL_PAGES}}",
"alignment": "center"
}
]
}
}
}Advanced Features
Dynamic Content
Use placeholders and expressions for dynamic content generation:
{
"content": [
{
"type": "paragraph",
"text": "Report generated on {{CURRENT_DATE}} for {{CLIENT_NAME}}"
},
{
"type": "conditional",
"condition": "show_summary",
"content": [
{
"type": "heading",
"level": 2,
"text": "Executive Summary"
}
]
}
],
"variables": {
"CURRENT_DATE": "{{DATE('YYYY-MM-DD')}}",
"CLIENT_NAME": "Acme Corporation",
"show_summary": true
}
}Table Data Binding
Automatically populate tables from data sources:
{
"type": "table",
"dataSource": "sales_data",
"mapping": {
"headers": ["Product", "Units Sold", "Revenue"],
"fields": ["product_name", "units", "total_revenue"]
},
"formatting": {
"numberFormat": {
"total_revenue": "$#,##0.00",
"units": "#,##0"
},
"conditional": {
"total_revenue": {
"rule": "> 10000",
"style": {"backgroundColor": "#D5E8D4"}
}
}
}
}Style Templates
Define reusable style templates:
{
"styleTemplates": {
"corporateHeading": {
"font": {"family": "Arial", "size": 16, "bold": true, "color": "#1F497D"},
"paragraph": {"spacing": {"before": 18, "after": 6}}
},
"highlightBox": {
"borders": {"all": {"style": "single", "color": "#4472C4", "width": 1}},
"shading": {"fill": "#E7F3FF"},
"paragraph": {"spacing": {"before": 6, "after": 6}}
}
}
}Document Templates
Template Structure
Create reusable templates with placeholders:
{
"templateStructure": {
"metadata": {
"name": "Business Report Template",
"version": "1.0",
"description": "Standard template for quarterly business reports"
},
"placeholders": [
"{{REPORT_TITLE}}",
"{{REPORT_PERIOD}}",
"{{EXECUTIVE_SUMMARY}}",
"{{FINANCIAL_DATA}}",
"{{RECOMMENDATIONS}}"
],
"sections": [
{
"name": "Cover Page",
"required": true,
"content": "cover_page_template"
},
{
"name": "Executive Summary",
"required": true,
"content": "summary_template"
},
{
"name": "Financial Analysis",
"required": false,
"content": "financial_template"
}
]
}
}Template Variables
Define variable types and validation:
{
"variableDefinitions": {
"REPORT_TITLE": {
"type": "string",
"required": true,
"validation": {"maxLength": 100}
},
"REPORT_DATE": {
"type": "date",
"format": "YYYY-MM-DD",
"defaultValue": "{{CURRENT_DATE}}"
},
"FINANCIAL_DATA": {
"type": "array",
"itemType": "object",
"fields": ["metric", "value", "change"]
}
}
}Performance Optimization
Batch Processing
Generate multiple documents efficiently:
{
"batchGeneration": {
"templateFile": "/sandbox/templates/report_template.docx",
"outputDirectory": "/sandbox/reports/batch",
"documents": [
{
"fileName": "report_client_a.docx",
"variables": {"client_name": "Client A", "data": "client_a_data"}
},
{
"fileName": "report_client_b.docx",
"variables": {"client_name": "Client B", "data": "client_b_data"}
}
],
"parallelProcessing": true,
"maxConcurrent": 5
}
}Memory Management
{
"performance": {
"memoryOptimization": true,
"streamProcessing": true,
"cacheTemplates": true,
"maxMemoryUsage": "256MB",
"processingTimeout": 300000
}
}Error Handling
Common Errors
| Error Type | Cause | Resolution |
|---|---|---|
TEMPLATE_NOT_FOUND | Template file doesn't exist | Verify template file path |
INVALID_CONTENT_TYPE | Unsupported content type | Check supported content types |
FORMATTING_ERROR | Invalid formatting specification | Validate formatting parameters |
VARIABLE_MISSING | Required template variable not provided | Provide all required variables |
MEMORY_EXCEEDED | Document too large for available memory | Optimize content or increase memory |
Error Response Format
{
"success": false,
"error": {
"type": "VARIABLE_MISSING",
"message": "Required template variable 'CLIENT_NAME' not provided",
"templateFile": "/sandbox/templates/invoice.docx",
"missingVariables": ["CLIENT_NAME", "INVOICE_DATE"],
"suggestions": [
"Provide all required variables in the variables object",
"Check template documentation for required variables",
"Use default values for optional variables"
]
}
}Usage Examples
Business Report Generation
{
"fileName": "q3_business_report.docx",
"content": [
{
"type": "heading",
"level": 1,
"text": "Q3 2024 Business Report",
"style": "Title"
},
{
"type": "paragraph",
"text": "Executive Summary",
"formatting": {"font": {"size": 14, "bold": true}}
},
{
"type": "paragraph",
"text": "This quarter showed significant growth across all key metrics..."
},
{
"type": "table",
"headers": ["Metric", "Q2 2024", "Q3 2024", "Change"],
"rows": [
["Revenue", "$1,200,000", "$1,500,000", "+25%"],
["New Customers", "45", "67", "+49%"],
["Customer Satisfaction", "4.2/5", "4.5/5", "+7%"]
]
},
{
"type": "pageBreak"},
{
"type": "image",
"source": "/sandbox/charts/revenue_chart.png",
"positioning": {"width": 500, "alignment": "center"},
"caption": {"text": "Figure 1: Revenue Growth Trend"}
}
]
}Invoice Template
{
"templateFile": "/sandbox/templates/invoice.docx",
"outputFile": "/sandbox/invoices/inv_2024_001.docx",
"variables": {
"invoice_number": "INV-2024-001",
"client_company": "ABC Corporation",
"client_address": "123 Business St, City, State 12345",
"invoice_date": "2024-03-15",
"due_date": "2024-04-15",
"line_items": [
{
"description": "Web Development Services",
"hours": 80,
"rate": 125,
"amount": 10000
},
{
"description": "Project Management",
"hours": 20,
"rate": 100,
"amount": 2000
}
],
"subtotal": 12000,
"tax_rate": 0.08,
"tax_amount": 960,
"total_amount": 12960
}
}Technical Documentation
{
"fileName": "api_documentation.docx",
"content": [
{
"type": "heading",
"level": 1,
"text": "API Documentation",
"style": "Title"
},
{
"type": "tableOfContents",
"style": "TOC1"
},
{
"type": "pageBreak"
},
{
"type": "heading",
"level": 2,
"text": "Authentication"
},
{
"type": "paragraph",
"text": "All API requests require authentication using API keys..."
},
{
"type": "codeBlock",
"language": "json",
"content": "{\n \"api_key\": \"your_api_key_here\",\n \"endpoint\": \"/api/v1/data\"\n}"
}
],
"formatting": {
"font": {"family": "Consolas", "size": 10},
"codeBlockStyle": {
"backgroundColor": "#F5F5F5",
"borders": true,
"font": {"family": "Courier New", "size": 9}
}
}
}Integration Patterns
With Data Analysis Tools
Generate reports from analysis results with automatic data visualization and chart insertion.
With File System Tools
Organize generated documents in structured directories with metadata and version control.
With Web Tools
Create documents from web-scraped data with automatic content formatting and layout.
Best Practices
Document Structure
- Use consistent heading styles and hierarchy
- Implement proper spacing and margins
- Organize content in logical sections
- Include table of contents for long documents
Template Design
- Create modular, reusable templates
- Use clear variable naming conventions
- Include default values for optional variables
- Document template requirements and usage
Performance
- Optimize image sizes and formats
- Use batch processing for multiple documents
- Cache templates for repeated use
- Monitor memory usage for large documents
Quality Assurance
- Validate content before generation
- Test templates with sample data
- Implement error handling and recovery
- Review generated documents for accuracy
Getting Started
- Define document structure and content requirements
- Create or select appropriate templates
- Prepare data sources and variables
- Configure formatting and style options
- Test document generation with sample data
- Implement batch processing if needed