PALATINELABSDocsENES

Pages

↑↓ to moveEnter to openEsc to close

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.

Jump to actions

Packages

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.

InputEditor fieldType; defaultUse
sessionSession nameStringdefault ""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.
passwordToOpenPassword to openCredentialdefault empty CredentialOptional. Leave empty. Password-protected files are not supported.
passwordToEditPassword to editCredentialdefault empty CredentialOptional. Leave empty. Password-protected files are not supported.
rangeRangeDocRangedefault FullDocumentOptional. FullDocument⁠: body paragraphs, tables included. ParagraphIndex⁠: 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). PageNumber always fails.
pageNumberPage numberNumberdefault 0Optional, shown only for range=PageNumber⁠. No page number works: choose a paragraph range.
paragraphIndexParagraph indexNumberdefault 0Optional. Paragraph number, from 1, used with range=ParagraphIndex⁠. Paragraphs in tables count. A number outside the document fails.
bookmarkNameBookmark nameStringdefault ""Optional. The exact existing bookmark name for a bookmark position or range. A missing name or marker fails.
matchCaseMatch caseBooleandefault falseOptional. true matches case; false ignores case.
wholeWordsMatch whole wordsBooleandefault falseOptional. true matches only when the characters beside the match are not letters, digits or _⁠; false also matches inside a longer word.
occurrenceText occurrence / Picture occurrenceOccurrencedefault AllOptional. All⁠, First or Last in document order. Search counts all matches before this selection; Format text counts the selected matches.
fontNameFont nameStringdefault ""Optional. Font family, such as Arial (it is not installed by the package). Empty keeps the font.
fontColorFont colorNumberdefault -1Optional. Decimal RGB, such as 65280 for 00FF00 green or 0 for black. -1 keeps the color.
fontSizeFont sizeNumberdefault 0Optional. Points, more than 0; 0 keeps the size.
fontBoldFont boldBooleandefault falseOptional. Bold style; see below.
fontItalicFont italicBooleandefault falseOptional. Italic style; see below.
fontUnderlinedFont underlinedBooleandefault falseOptional. Underline style; see below.
widthWidthNumberdefault 0Optional. 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.
heightHeightNumberdefault 0Optional. The same size rules as width⁠.
includeHeadersInclude column headersBooleandefault falseOptional. 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.

Actions

Close (wordCloseDocument)

Ends the named document session. Choose whether unsaved edits are written or discarded.

Inputs

Uses the shared fields: session.

InputEditor fieldType and runtime defaultUse
saveChangesSave changes before closing document.Boolean⁠; falseOptional. 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.

Back to actions

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.

InputEditor fieldType and runtime defaultUse
filePathFile pathString⁠; ""Required. Destination with extension .docx⁠, such as samples/report.docx⁠. Relative paths use the Run working folder. Create writes immediately, creates missing parent folders and replaces an existing file.

Outputs

OutputTypeMeaning and binding
sessionNameStringThe 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.

Back to actions

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.

InputEditor fieldType and runtime defaultUse
pictureTitleToFindAlt textString⁠; ""Required. Exact, case-sensitive picture description or name, such as logo⁠. An empty value is refused.
replacePictureReplace pictureBoolean⁠; falseOptional. true replaces selected pictures and requires a writable session plus a replacement image. false only counts matching pictures.
selectPictureToReplaceSelect pictureString⁠; ""Optional. Image files.
altTextToReplaceAlt textString⁠; ""Optional. Nonempty text replaces both name and description on each changed picture. Empty preserves the existing text.

Outputs

OutputTypeMeaning and binding
countNumberAll 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.

Back to actions

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.

InputEditor fieldType and runtime defaultUse
textToFindFind textString⁠; ""Required. Literal search.
isReplaceReqioredReplace textBoolean⁠; falseOptional. true replaces the chosen text matches and needs a writable session. false only returns their total count.
textToReplaceReplace withString⁠; ""Optional. Enter the replacement text. An empty value deletes the selected matching text when replacement is enabled.

Outputs

OutputTypeMeaning and binding
countNumberAll 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.

Back to actions

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.

InputEditor fieldType and runtime defaultUse
textToFindText to formatString⁠; ""Required. Literal search.

Outputs

OutputTypeMeaning and binding
countNumberNumber 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.

Back to actions

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.

InputEditor fieldType and runtime defaultUse
imagePathPicture pathString⁠; ""Required. Image files.
alternativeTextAlt textString⁠; ""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.
insertAtInsert positionInsertPosition⁠; EndOptional. 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.

Back to actions

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.

InputEditor fieldType and runtime defaultUse
tableNameTable titleString⁠; ""Optional. Table title.
positionInsert positionTablePosition⁠; AtCurrentOptional. AtCurrent appends the table at the end of the document body. Bookmark inserts the table after the paragraph that contains the named bookmark. Choices: AtCurrent⁠, Bookmark⁠.
sourceTableSource tableTable⁠; empty TableRequired. 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.

Back to actions

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.

InputEditor fieldType and runtime defaultUse
positionInsert positionInsertPosition⁠; EndOptional. Text/picture position.
textTypeText to insertTextType⁠; PlainTextOptional. Use PlainText⁠. Html is an editor choice but always raises an unsupported-operation error. Choices: PlainText⁠, Html⁠.
messageTextString⁠; ""Optional. Enter nonempty plain text, such as Monthly report⁠. Leading and trailing spaces are preserved. Insertion creates a paragraph except at a bookmark.
htmlContentTextString⁠; ""Optional. Shown only for textType=Html⁠. 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.

Back to actions

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.

InputEditor fieldType and runtime defaultUse
filePathFileString⁠; ""Required. Path to an existing .docx file, such as samples/report.docx⁠. Relative paths use the Run working folder. Other extensions are refused.
openInOpen inOpenIn⁠; ReadWriteOptional. ReadWrite permits edits and Save. ReadOnly permits reading, searching without replacement, and Save as to make a copy. Choices: ReadWrite⁠, ReadOnly⁠.

Outputs

OutputTypeMeaning and binding
sessionNameStringThe 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.

Back to actions

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.

InputEditor fieldType and runtime defaultUse
tableNameTable titleString⁠; ""Required. Table title.
rangeRangeTableRange⁠; FullTableOptional. FullTable reads every row and column. RowsAndColumns selects the inclusive one-based row and column bounds below before deciding whether the first selected row is a header. Choices: FullTable⁠, RowsAndColumns⁠.
startingRowStart row numberNumber⁠; 1Optional. One-based first row, inclusive, used only for RowsAndColumns⁠.
endingRowEnd row numberNumber⁠; 1Optional. One-based last row, inclusive, used only for RowsAndColumns⁠.
startingColumnStart column numberNumber⁠; 1Optional. One-based first column, inclusive, used only for RowsAndColumns⁠.
endingColumnEnd column numberNumber⁠; 1Optional. One-based last column, inclusive, used only for RowsAndColumns⁠.

Outputs

OutputTypeMeaning and binding
resultTableTable of selected cells. Headers, when enabled, define String column names and are removed from data rows. Bind to a Table variable such as readPeople⁠.

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.

Back to actions

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

OutputTypeMeaning and binding
textStringSelected paragraph text, joined with line feeds. Bind to a String variable such as paragraphText⁠.

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.

Back to actions

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.

Back to actions

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.

InputEditor fieldType and runtime defaultUse
filePathFile pathString⁠; ""Required. Destination for the .docx copy, such as samples/report-copy.docx⁠. Relative paths use the Run working folder. Missing parent folders are created. Other extensions are refused; the original session path stays unchanged.
overwriteOverwrite existing fileBoolean⁠; falseOptional. 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.

Back to actions