Word package guide
Create, read and edit DOCX documents with named working-copy sessions.
Version 2.17.1. Installed versions can differ. Examples are illustrative and not tested.
Prerequisites
Works on .docx files. Microsoft Word does not need to be installed. .doc, .rtf, PDF export, HTML export, encrypted files, HTML insertion and page ranges are not supported. The package stores document content; it does not render or paginate it.
Create or Open a session with a name that is not empty such as doc. Later actions use that same name in the same Run. Changes stay in a working copy until Save, Save as, or Close with saving. Create writes its empty file immediately and can replace an existing file. Save as writes a copy and keeps the original save path. Use Close to release each session.
For the examples, use test files in samples/. Prepare samples/logo.png and samples/banner.png. Prepare a Table variable $people$ with String columns name, city and rows ada, london and linus, helsinki. Bind this Table directly; do not pass a plain String variable. Bookmark examples require a template that already contains the named bookmark. The package has no action to create bookmarks.
To make a report: Create document with Session name=doc, File path=samples/report.docx; Insert text with Session name=doc, Text=Monthly report; Save with Session name=doc; then Close with Session name=doc.
Shared fields
Actions name the fields they use from this table.
| Input | Editor field | Type; default | Use |
|---|---|---|---|
session | Session name | Stringdefault "" | Optional in the editor, but a local name such as doc (not empty) is needed. Use the exact name from Open or Create in this Run. Close it before reusing the name. This is not a credential. An unknown session fails. |
password | Password to open | Credentialdefault empty Credential | Optional. Leave empty. Password-protected files are not supported. |
password | Password to edit | Credentialdefault empty Credential | Optional. Leave empty. Password-protected files are not supported. |
range | Range | Docdefault Full | Optional. Full: body paragraphs, tables included. Paragraph: one paragraph, counted from 1. Bookmark: whole paragraphs from the bookmark start to its end (fails in text search actions, which have no bookmark input). Page always fails. |
page | Page number | Numberdefault 0 | Optional, shown only for range=. No page number works: choose a paragraph range. |
paragraph | Paragraph index | Numberdefault 0 | Optional. Paragraph number, from 1, used with range=. Paragraphs in tables count. A number outside the document fails. |
bookmark | Bookmark name | Stringdefault "" | Optional. The exact existing bookmark name for a bookmark position or range. A missing name or marker fails. |
match | Match case | Booleandefault false | Optional. true matches case; false ignores case. |
whole | Match whole words | Booleandefault false | Optional. true matches only when the characters beside the match are not letters, digits or _; false also matches inside a longer word. |
occurrence | Text occurrence / Picture occurrence | Occurrencedefault All | Optional. All, First or Last in document order. Search counts all matches before this selection; Format text counts the selected matches. |
font | Font name | Stringdefault "" | Optional. Font family, such as Arial (it is not installed by the package). Empty keeps the font. |
font | Font color | Numberdefault -1 | Optional. Decimal RGB, such as 65280 for 00 green or 0 for black. -1 keeps the color. |
font | Font size | Numberdefault 0 | Optional. Points, more than 0; 0 keeps the size. |
font | Font bold | Booleandefault false | Optional. Bold style; see below. |
font | Font italic | Booleandefault false | Optional. Italic style; see below. |
font | Font underlined | Booleandefault false | Optional. Underline style; see below. |
width | Width | Numberdefault 0 | Optional. Inches. Set both dimensions above 0 for an exact size (can distort the image). One 0 uses the image proportions; both 0 use the pixel size at 96 dpi. |
height | Height | Numberdefault 0 | Optional. The same size rules as width. |
include | Include column headers | Booleandefault false | Optional. Insert: true adds a bold row of source column names. Read: true uses the first selected row as column names; false keeps it as data and creates column names. |
Bold, Italic, Underline: true adds the style. false keeps the text as it is; it does not remove the style.
- Images (
selectPictureToReplace,imagePath): An existing.png,.jpg,.jpeg,.gifor.bmpfile. Relative paths start in the Run working folder. SVG and other formats fail. A replacement path is needed when replacement is on, even if nothing matches. - Text search (
textToFind): Text that is not empty, such ascat. Searches inside each paragraph, also across its text runs, but not across paragraphs. - Text/picture position (
insertAt,position):Startinserts at the start;Endappends;Bookmarkinserts after the named bookmark start;Currentalso appends (there is no cursor). - Table title (
tableName): A caption that is not empty, such asPeople. Insert writes it. Read first finds the exact caption, then accepts an index from 1, such as1orTable1.
Actions
Close (wordCloseDocument)
Ends the named document session. Choose whether unsaved edits are written or discarded.
Inputs
Uses the shared fields: session.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
save | Save changes before closing document. | Boolean; false | Optional. true saves the working copy to the original path before closing. false discards changes since the last save. Saving requires a writable session. |
Outputs
No output variables.
Example
After editing doc, set Session name=doc, Save changes before closing document = true.
Expected result
Edits are written to samples/report.docx and the session is closed. With false, edits since the last save are lost. Saving a read-only session fails.
Create document (wordCreateDocument)
Creates an empty document and opens it for editing. Use a test destination because Create replaces an existing file.
Inputs
Uses the shared fields: session, passwordToOpen, passwordToEdit.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
file | File path | String; "" | Required. Destination with extension .docx, such as samples/. Relative paths use the Run working folder. Create writes immediately, creates missing parent folders and replaces an existing file. |
Outputs
| Output | Type | Meaning and binding |
|---|---|---|
session | String | The exact session name. Bind to a String or use the same name in later steps. |
Example
Set Session name=doc, File path=samples/report.docx. Leave both password fields unset. Bind sessionName to a String variable named wordSession.
Expected result
An empty .docx is written immediately; sessionName is doc. The session is writable. An extension other than .docx fails.
Find and replace picture (wordFindAndReplacePicture)
Finds pictures by exact alt text or name. It can count them or replace the selected occurrences in the working copy.
Inputs
Uses the shared fields: session, range, pageNumber, paragraphIndex, bookmarkName, width, height, occurrence.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
picture | Alt text | String; "" | Required. Exact, case-sensitive picture description or name, such as logo. An empty value is refused. |
replace | Replace picture | Boolean; false | Optional. true replaces selected pictures and requires a writable session plus a replacement image. false only counts matching pictures. |
select | Select picture | String; "" | Optional. Image files. |
alt | Alt text | String; "" | Optional. Nonempty text replaces both name and description on each changed picture. Empty preserves the existing text. |
Outputs
| Output | Type | Meaning and binding |
|---|---|---|
count | Number | All matches before occurrence selection, also when replacing; 0 if none. |
Example
First insert one picture with Alt text=logo in doc. Set Session name=doc, Alt text (pictureTitleToFind)=logo, Range=FullDocument, Replace picture=true, Select picture=samples/banner.png, Alt text (altTextToReplace)=banner, Width=2, Height=1, Picture occurrence=All. Bind count to picturesFound, then Save.
Expected result
count is 1; the picture becomes a 2 by 1 inch banner with name and description banner.
Find and replace text (wordFindAndReplaceText)
Counts literal text matches and can replace the chosen occurrences.
Inputs
Uses the shared fields: session, matchCase, wholeWords, range, pageNumber, paragraphIndex, occurrence.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
text | Find text | String; "" | Required. Literal search. |
is | Replace text | Boolean; false | Optional. true replaces the chosen text matches and needs a writable session. false only returns their total count. |
text | Replace with | String; "" | Optional. Enter the replacement text. An empty value deletes the selected matching text when replacement is enabled. |
Outputs
| Output | Type | Meaning and binding |
|---|---|---|
count | Number | All matches before occurrence selection, also when replacing; 0 if none. |
Example
In doc, insert the paragraph the cat and the cattle. Set Find text=cat, Match case=false, Match whole words=false, Range=FullDocument, Replace text=true, Replace with=dog, Text occurrence=All, Session name=doc. Bind count to matches and Save.
Expected result
count is 2; the paragraph becomes the dog and the dogtle. Whole-word matching would find only the separate cat. No matches returns 0 without changing the text.
Format text (wordFormatText)
Styles selected literal matches without changing their text. It needs a writable session.
Inputs
Uses the shared fields: session, matchCase, wholeWords, range, pageNumber, paragraphIndex, occurrence, fontName, fontColor, fontSize, fontBold, fontItalic, fontUnderlined.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
text | Text to format | String; "" | Required. Literal search. |
Outputs
| Output | Type | Meaning and binding |
|---|---|---|
count | Number | Number of selected matches formatted; 0 if none. |
Example
Insert plain BOLD plain in doc. Set Session name=doc, Text to format=BOLD, Match case=true, Range=FullDocument, Text occurrence=First, Font name=Arial, Font color=65280, Font size=16, Font bold=true. Bind count to formatted and Save.
Expected result
count is 1. Only BOLD becomes Arial, 16 pt, green and bold; all text stays plain BOLD plain.
Insert picture (wordInsertPicture)
Adds an inline picture at the start, end or an existing bookmark. Use alt text so later actions can find the image.
Inputs
Uses the shared fields: session, width, height, bookmarkName.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
image | Picture path | String; "" | Required. Image files. |
alternative | Alt text | String; "" | Optional. Descriptive alt text, such as logo. It is stored as both image name and description for later picture searches. Empty uses a generated image name and an empty description. |
insert | Insert position | Insert; End | Optional. Text/picture position. |
Outputs
No output variables.
Example
In the writable doc session, set Picture path=samples/logo.png, Alt text=logo, Width=2, Height=1, Insert position=End, Session name=doc. Save afterwards.
Expected result
A picture is appended in a new paragraph, sized 2 by 1 inches, with name and description logo.
Insert table (wordInsertTable)
Writes a Table variable into the document, with a caption used by Read table. The current position appends because there is no cursor.
Inputs
Uses the shared fields: session, bookmarkName, includeHeaders.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
table | Table title | String; "" | Optional. Table title. |
position | Insert position | Table; At | Optional. At appends the table at the end of the document body. Bookmark inserts the table after the paragraph that contains the named bookmark. Choices: At, Bookmark. |
source | Source table | Table; empty Table | Required. Bind a populated Table variable, for example $people$. Column names become header text when headers are enabled. Cell values become text in the document. |
Outputs
No output variables.
Example
Prepare $people$ as described in Prerequisites. In doc, set Table title=People, Insert position=AtCurrent, Source table=$people$, Include column headers=true, Session name=doc. Save.
Expected result
The appended table has two columns and three rows, including a bold name, city header. It has caption People and a following empty paragraph. A blank table title fails even though the editor does not mark it required.
Insert text (wordInsertText)
Adds nonempty plain text to the working copy. HTML insertion is not supported.
Inputs
Uses the shared fields: session, bookmarkName, fontName, fontColor, fontSize, fontBold, fontItalic, fontUnderlined.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
position | Insert position | Insert; End | Optional. Text/picture position. |
text | Text to insert | Text; Plain | Optional. Use Plain. Html is an editor choice but always raises an unsupported-operation error. Choices: Plain, Html. |
message | Text | String; "" | Optional. Enter nonempty plain text, such as Monthly report. Leading and trailing spaces are preserved. Insertion creates a paragraph except at a bookmark. |
html | Text | String; "" | Optional. Shown only for text. This field cannot be used successfully in this version. Put plain text in message instead. |
Outputs
No output variables.
Example
After Create document for doc, set Session name=doc, Insert position=End, Text to insert=PlainText, Text (message)=Monthly report, Font name=Arial, Font size=12, Font bold=true. Save.
Expected result
A paragraph containing Monthly report is appended in Arial 12 pt bold. Current would also append. Empty text, Html, a missing bookmark or a read-only session causes an error.
Open (wordOpenDocument)
Opens an existing .docx in a named session by copying it to a working file.
Inputs
Uses the shared fields: session, passwordToOpen, passwordToEdit.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
file | File | String; "" | Required. Path to an existing .docx file, such as samples/. Relative paths use the Run working folder. Other extensions are refused. |
open | Open in | Open; Read | Optional. Read permits edits and Save. Read permits reading, searching without replacement, and Save as to make a copy. Choices: Read, Read. |
Outputs
| Output | Type | Meaning and binding |
|---|---|---|
session | String | The exact session name. Bind to a String or use the same name in later steps. |
Example
Set Session name=doc, File=samples/report.docx, Open in=ReadOnly. Leave passwords unset and bind sessionName to wordSession.
Expected result
sessionName is doc. Read text can use the session; edit actions and Save fail. A missing file or an extension other than .docx fails.
Read table (wordReadTable)
Read a document table into a Table variable. Select rows and columns before taking the header. Bounds count from 1, and both ends are included. Reversed ends are swapped; an end below 1 becomes 1. A selection beyond the cells can give an empty table or short rows.
Inputs
Uses the shared fields: session, includeHeaders.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
table | Table title | String; "" | Required. Table title. |
range | Range | Table; Full | Optional. Full reads every row and column. Rows selects the inclusive one-based row and column bounds below before deciding whether the first selected row is a header. Choices: Full, Rows. |
starting | Start row number | Number; 1 | Optional. One-based first row, inclusive, used only for Rows. |
ending | End row number | Number; 1 | Optional. One-based last row, inclusive, used only for Rows. |
starting | Start column number | Number; 1 | Optional. One-based first column, inclusive, used only for Rows. |
ending | End column number | Number; 1 | Optional. One-based last column, inclusive, used only for Rows. |
Outputs
| Output | Type | Meaning and binding |
|---|---|---|
result | Table | Table of selected cells. Headers, when enabled, define String column names and are removed from data rows. Bind to a Table variable such as read. |
Example
After the People table example, set Session name=doc, Table title=People, Range=FullTable, Include column headers=true. Bind result to a Table variable readPeople. To read only data in the first column, choose RowsAndColumns, rows 2 through 3, columns 1 through 1, headers=false.
Expected result
FullTable returns columns name, city and the two data rows. The slice returns two rows containing ada and linus in one generated column. A missing table fails; an out-of-range selection can return no rows.
Read text (wordReadText)
Reads the text from selected body paragraphs. It joins paragraphs with a line feed and includes text in table paragraphs.
Inputs
Uses the shared fields: session, range, pageNumber, paragraphIndex, bookmarkName.
Outputs
| Output | Type | Meaning and binding |
|---|---|---|
text | String | Selected paragraph text, joined with line feeds. Bind to a String variable such as paragraph. |
Example
In doc, insert three paragraphs one, two, three in that order. Set Session name=doc, Range=ParagraphIndex, Paragraph index=2. Bind text to a String variable paragraphText.
Expected result
text is two. FullDocument would return the three paragraphs separated by line feeds. An empty document returns empty text for FullDocument. An invalid paragraph, missing bookmark or PageNumber range fails.
Save (wordSaveDocument)
Writes the working copy back to the file used by Create or Open. The session stays open.
Inputs
Uses the shared fields: session.
Outputs
No output variables.
Example
After adding Monthly report in the writable doc session created at samples/report.docx, set Session name=doc.
Expected result
samples/report.docx now contains the current working-copy changes. A read-only session fails.
Save as (wordSaveDocumentAs)
Saves a .docx copy to another path. It can copy a read-only session and does not change its original save path.
Inputs
Uses the shared fields: session.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
file | File path | String; "" | Required. Destination for the .docx copy, such as samples/. Relative paths use the Run working folder. Missing parent folders are created. Other extensions are refused; the original session path stays unchanged. |
overwrite | Overwrite existing file | Boolean; false | Optional. Set true only to replace the destination file. With false, an existing destination causes an error. Save as does not change the session's original save path. |
Outputs
No output variables.
Example
With doc open, set Session name=doc, File path=samples/report-copy.docx, Overwrite existing file=false.
Expected result
A copy is written to samples/report-copy.docx. A later Save still targets samples/report.docx. An existing destination fails unless overwrite is true; PDF, HTML, DOC and RTF destinations fail.