Skip to main content

Clear Word

Clears all content from the Word document, removing all text, images, tables, and other elements. This operation empties the document body while preserving headers and footers.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing the node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.

Input

  • File Descriptor - File descriptor ID from the Open Word node. Default variable is word_fd.

Use Cases

  • Resetting template documents to blank state
  • Clearing document content before regenerating
  • Removing all data before repopulating with new content
  • Preparing documents for fresh content insertion
  • Cleaning up test documents
  • Implementing "start from scratch" functionality in workflows

Example

Clearing and rebuilding a document:

  1. Use Open Word to open an existing document
  2. Add the Clear Word node to remove all content
  3. Add content using Add Text, Add Heading, Add Table, etc.
  4. Use Close Word to save the document

Workflow Example: Document Regeneration

// Step 1: Open existing document
// Use Open Word: C:\Reports\MonthlyReport.docx

// Step 2: Clear all existing content
// Use Clear Word with word_fd

// Step 3: Add new content
// Add Heading: "Monthly Sales Report - December 2024"
// Add Text: "This report summarizes..."
// Add Table: salesData

// Step 4: Save and close
// Use Close Word with Save Changes: true

Template Reset Example

// Workflow for resetting a template
// 1. Open template document
// 2. Clear all content (removes old data)
// 3. Replace with new template structure
// 4. Save as new template version
warning

This operation is irreversible within the automation flow. Ensure you have saved the document or created a backup before clearing if you need to preserve the original content.

What Gets Cleared

The Clear Word node removes:

  • All text content
  • All paragraphs
  • All tables
  • All images and shapes
  • All formatting in the body
  • All lists and numbering
  • All content controls

What Gets Preserved

The Clear Word node preserves:

  • Headers (top of pages)
  • Footers (bottom of pages)
  • Document sections
  • Page setup (margins, orientation)
  • Styles definitions
  • Document metadata

Use with Conditional Logic

// Clear document only if certain conditions are met
if (rebuildRequired) {
// Use Clear Word node
// Then rebuild content
} else {
// Use Replace Text to update existing content
}

Common Errors

  • "Invalid File Descriptor" - Ensure the Open Word node was executed first and the file descriptor is valid.
  • Document is read-only - Ensure the document is not marked as read-only in the file system.

Notes

  • The clearing operation is immediate and cannot be undone within the automation.
  • After clearing, the document is completely empty (except headers/footers).
  • The document remains open after clearing - you can add new content immediately.
  • To also clear headers and footers, add new headers/footers after clearing or manually delete them.

Best Practices

  • Use Clear Word when you need a completely fresh document body.
  • Consider using Replace Text instead if you only need to update specific content.
  • Always ensure the file descriptor is valid before clearing.
  • When clearing templates, maintain a backup of the original template file.
  • Test the clearing operation on a copy before using on production documents.
  • Consider whether you truly need to clear all content or just replace specific sections.

Alternatives to Consider

  • Replace Text - For updating specific content without removing everything
  • Delete specific elements - For removing only certain types of content
  • Create new document - If you need a completely fresh start, consider creating a new document instead

Typical Use Cases

Case 1: Monthly Report Generation

// Open last month's report
// Clear all old content
// Add current month's data
// Save with new filename

Case 2: Template Refresh

// Open template
// Clear outdated sample content
// Add new sample data
// Save template

Case 3: Data Export Reset

// Open export document
// Clear previous export data
// Add new query results
// Export to PDF

See Also