logo_smallAxellero.io

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:

ParameterTypeRequiredDescription
outputDirectoryTEXTNoDefault directory for generated documents
templateDirectoryTEXTNoDirectory containing document templates
defaultFontTEXTNoDefault font family for documents (default: Calibri)
defaultFontSizeINTNoDefault font size in points (default: 11)

Methods

createDocument

Generate a new DOCX document with specified content and formatting.

ParameterTypeRequiredDescription
fileNameTEXTYesName for the generated document
contentArrayYesDocument content structure
formattingObjectNoGlobal document formatting options
metadataObjectNoDocument 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 status
  • filePath (String) - Path to the generated document
  • pageCount (Number) - Number of pages in the document
  • wordCount (Number) - Total word count
  • metadata (Object) - Document properties and statistics

modifyDocument

Edit existing DOCX documents by adding, replacing, or removing content.

ParameterTypeRequiredDescription
inputFileTEXTYesPath to the source document
outputFileTEXTYesPath for the modified document
operationsArrayYesList of modification operations
preserveFormattingBOOLEANNoKeep 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.

ParameterTypeRequiredDescription
templateFileTEXTYesPath to the template document
outputFileTEXTYesPath for the generated document
variablesObjectYesVariables for template substitution
conditionalContentObjectNoRules 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 TypeDescriptionParameters
headingDocument headings with styleslevel, text, style, numbering
paragraphText paragraphs with formattingtext, alignment, spacing, indentation
listBulleted or numbered listsitems, type, style, level
textInline text with stylingtext, 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 TypeCauseResolution
TEMPLATE_NOT_FOUNDTemplate file doesn't existVerify template file path
INVALID_CONTENT_TYPEUnsupported content typeCheck supported content types
FORMATTING_ERRORInvalid formatting specificationValidate formatting parameters
VARIABLE_MISSINGRequired template variable not providedProvide all required variables
MEMORY_EXCEEDEDDocument too large for available memoryOptimize 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

  1. Define document structure and content requirements
  2. Create or select appropriate templates
  3. Prepare data sources and variables
  4. Configure formatting and style options
  5. Test document generation with sample data
  6. Implement batch processing if needed

Resources