Skip to content

Word Activities

Version: 1.0.4  ·  ID: zoan-packages-word  ·  Author: Zoan Software

The Word package reads and creates .docx documents working directly on the file, without needing Microsoft Word installed (only Word to PDF needs LibreOffice or Microsoft Word). Its two main uses:

  • Read documents: extract their text, paragraphs and tables for processing.
  • Generate documents: create letters, contracts, reports or minutes from data, combining styled paragraphs, tables and images.

As in Excel, there are two ways to work:

The read and one-off change activities accept a path directly: they open the file, do the operation and close it. Ideal for a single operation.

Word Read Text path = asset("contract.docx") → output: text

For several operations on the same document —and required to build a new document— you open a session with Word Open (existing document) or Word Create (new document), and share that session with the other activities.

Word Create path = "C:/output/report.docx"
└─ body:
Word Append Paragraph text = "Monthly report" style = Title
Word Append Table table = data

Inside the body, activities inherit the session automatically, and when it ends the document is saved and closed by itself (with Create, if the body finished without errors) or closed without saving (with Open: put a Word Save inside the body if you changed it).

The session works on an in-memory copy of the document: changes reach the disk only when you save, and the file is not locked meanwhile. In quick mode, the activities that change the document (Find & Replace, Set Property) save to the same path when they finish; the read activities don’t touch the file.

When adding paragraphs with Word Append Paragraph, you can apply a style that gives the document visual structure:

StylePurpose
TitleThe main title of the document
Heading1 / Heading2 / Heading3Section headings (levels)
NormalBody text (default)

The style is assigned by its identifier, so its look depends on the document defining it. Documents made in Word include these styles; a new document from Word Create has no style definitions. If you want headings with a specific format, prepare a template in Word and open it with Word Open.

ActivityTypeOutputWhat it does
Word Openword-openZoanWordSessionOpens an existing .docx (does not save on close)
Word Createword-createZoanWordSessionCreates a new .docx (with body, saves it at the end)
Word Save (Session)word-save—Saves the session to disk, to its path or another one
Word Close (Session)word-close—Closes the session without saving
ActivityTypeOutputWhat it does
Word Read Textword-read-textstringAll the text of the document
Word Read Paragraphsword-read-paragraphsList<object>List of paragraphs (text)
Word Read Tablesword-read-tablesList<DataTable>The tables as DataTables
ActivityTypeOutputWhat it does
Word Append Paragraphword-append-paragraph—Appends a paragraph (with a style)
Word Append Tableword-append-table—Appends a DataTable as a table
Word Insert Imageword-insert-image—Inserts an image
ActivityTypeOutputWhat it does
Word Find & Replaceword-find-replaceintFinds and replaces text; returns how many fragments changed
Word Get Propertyword-get-propertyobjectReads a metadata field (title, author…)
Word Set Propertyword-set-property—Sets a metadata field
ActivityTypeOutputWhat it does
Word to PDFword-to-pdfstringConverts a document to PDF (requires LibreOffice or Microsoft Word)

Generate a letter from a template with placeholders:

Copy File source = asset("letter_template.docx") destination = "C:/letters/" + customer.id + ".docx" overwrite = true
Word Find & Replace path = "C:/letters/" + customer.id + ".docx" find = "{NAME}" replace = customer.name
Word Find & Replace path = "C:/letters/" + customer.id + ".docx" find = "{DATE}" replace = today().ToString("yyyy-MM-dd")