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.
Concept 1: quick mode vs. session mode
Section titled “Concept 1: quick mode vs. session mode”As in Excel, there are two ways to work:
Quick mode (path)
Section titled “Quick mode (path)”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: textSession mode (session)
Section titled “Session mode (session)”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 = dataInside 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.
Concept 2: paragraph styles
Section titled “Concept 2: paragraph styles”When adding paragraphs with Word Append Paragraph, you can apply a style that gives the document visual structure:
| Style | Purpose |
|---|---|
Title | The main title of the document |
Heading1 / Heading2 / Heading3 | Section headings (levels) |
Normal | Body 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.
Activities
Section titled “Activities”Session (open, create, save, close)
Section titled “Session (open, create, save, close)”| Activity | Type | Output | What it does |
|---|---|---|---|
| Word Open | word-open | ZoanWordSession | Opens an existing .docx (does not save on close) |
| Word Create | word-create | ZoanWordSession | Creates 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 |
| Activity | Type | Output | What it does |
|---|---|---|---|
| Word Read Text | word-read-text | string | All the text of the document |
| Word Read Paragraphs | word-read-paragraphs | List<object> | List of paragraphs (text) |
| Word Read Tables | word-read-tables | List<DataTable> | The tables as DataTables |
Build content (session required)
Section titled “Build content (session required)”| Activity | Type | Output | What it does |
|---|---|---|---|
| Word Append Paragraph | word-append-paragraph | — | Appends a paragraph (with a style) |
| Word Append Table | word-append-table | — | Appends a DataTable as a table |
| Word Insert Image | word-insert-image | — | Inserts an image |
Modify and metadata
Section titled “Modify and metadata”| Activity | Type | Output | What it does |
|---|---|---|---|
| Word Find & Replace | word-find-replace | int | Finds and replaces text; returns how many fragments changed |
| Word Get Property | word-get-property | object | Reads a metadata field (title, author…) |
| Word Set Property | word-set-property | — | Sets a metadata field |
Convert
Section titled “Convert”| Activity | Type | Output | What it does |
|---|---|---|---|
| Word to PDF | word-to-pdf | string | Converts a document to PDF (requires LibreOffice or Microsoft Word) |
A typical flow
Section titled “A typical flow”Generate a letter from a template with placeholders:
Copy File source = asset("letter_template.docx") destination = "C:/letters/" + customer.id + ".docx" overwrite = trueWord Find & Replace path = "C:/letters/" + customer.id + ".docx" find = "{NAME}" replace = customer.nameWord Find & Replace path = "C:/letters/" + customer.id + ".docx" find = "{DATE}" replace = today().ToString("yyyy-MM-dd")Next steps
Section titled “Next steps”- Word Create — generate a document from scratch.
- Word Read Text — read a document.
- Word Find & Replace — fill in templates.