# Office
# Overview
The Office category of actions provides for working with Microsoft Office documents and related formats.
Word Document generation involves two methods of content generation depending on goals, and which can be used as needed. One method involves “replacement fields”, like a form letter, which provides for simple set of target fields to be replaced with new data. Another method involves generation of tables, typically for report data.
# Getting Started
The process of generating Word documents in workflow starts with using Microsoft Word to define a template for your new document. Once this document is created, it can then be stored as a file asset for the workflow to use. Any workflow may then use the template to generate documents by first copying the file asset into a file variable with the “Set File Variable with Asset”. To define a file asset, access the menu “Manage”, “File Assets” from the designer menu bar. The dialog will present options to upload documents and provide a reference name for the document file asset.
# Replacing Fields
The field replacement method allows for a form letter style replacement of target fields with new data in workflow. To get started, create a Word document and declare “fields” by specifying any text you would like to replace in workflow. A document template can be defined with any number of replacement targets. A simple format to follow is to define replacement target fields with square-brackets and all-caps, no spaces. This is not a requirement, but it may help with consistency and troubleshooting. An example document is below using [SUPPLIERNAME] and other targets as needed
After defining a source template document, uploading the document as a file asset, then setting the asset into a file variable, that file variable can then be used in a “Word Replace Fields” action. The “Word Replace Fields” action has a property “Fields to replace”, which then is a simple table of the field to replace and the new value.
# Creating Tables
Creating tables in a Word document starts with creating table “segments” within Word. These segments are then assembled into new tables in the final document. Table formatting options may be used, including cell backgrounds, table borders, colors, and fonts. The workflow will then fill the templates with the information. By combining multiple source table templates together, complex new tabular reports can be generated including one or more header lines, segments of data, and one or more summary lines. Additionally, as tables are created, formatting options are available to inject spacing as paragraph and page breaks. Adding new tables to a document is done with the “Word Add Table” action. Rows are added to tables added with the “Word Append to Table” action. Finally, once a document is fully generated, the “Word Delete Table” action is used to remove any temporary template tables that are no longer needed.
To set up a Word document using tables as templates, add the tables to the document and set any needed formatting. These table templates can also contain text, as the text will be replaced by the workflow later. For each table to use as a template, an identifier must be defined so the workflow can use it at runtime. The below example table and its properties defines “TableHeaderLight” to be the ID to be used by the “Word Add Table” action.
Example Table as template:
LOC | BAL | Receipts | AAA | Close Balance | Gain/Loss |
---|---|---|---|---|---|
AA | AA | AA | AA | ZZ | ZZ |
TableReport1
Setting the “ID” for the table template in the table properties
# Word Replace Fields
Action Function: The Word Replace Fields will replace target “Fields” in a template Word document.
Action Outputs:
Successful – The action ran without error
Unsuccessful – there was some issue in the action execution
Action Properties:
Label
This property designates the name of the action or step as shown within the workflow design.
Source file variable
Specifies which file variable contains the document with fields to be replaced
Target file variable
Specifies the file variable to store the new document with replaced fields. This can be the same variable as the source file variable.
Fields to replace
This property allows the designer to specify one or more fields to be replaced in the template document. “Fields to replace” contains are the text strings to be replaced in the source document, e.g. [TITLE], [STARTDATE], etc. The corresponding “Value” input determines the value to use to replace the original replacement text.
# Word Add Table
Action Function: The Word Add Table will generate a new table in a Word document using a specified source table as a style and layout template.
Action Outputs:
Successful – The action ran without error
Unsuccessful – there was some issue in the action execution
Action Properties:
Label
This property designates the name of the action or step as shown within the workflow design.
Template Table ID
This property specifies which table in the document will be used as a style and layout template for the new table. The ID must match what has been set for the table in the source Word document using the “Alt Text” property for the table.
New Table ID
This property specifies an ID to use for the newly generated table which will be added to the Word document. This ID is optional but is needed if additional rows will be added to the table with the “Word Add Table” action later. This ID will be stored into the generated table’s Alt Text property.
New Table Description
This property will set a description for the newly generated table which is accessible in the table’s properties in Word.
Source file variable
Specifies which file variable contains the document which contains the Table Template ID to use
Target file variable
Specifies the file variable to store the new document with the newly added table. This can be the same variable as the source file variable.
Skip first row
This option, ‘true’ or ‘false’, determines if the first row of the table is to be skipped over when adding new data to the table. Specifying ‘true’ allows the source table template to provide a fixed ‘header’ row.
Append Paragraph
This property determines if a Word “Paragraph” should be added after the new table.
Append Page Break
This property determines if a Word “Page Break” should be added after the new table.
New Table Data
This property specifies the source JSON document with one or more rows of data to be added to the newly generated table.
Cell properties available are:
Value: The text for the cell
Color: the color for the cell. Values are given as hex, in RRGGBB format.
Font: The font name for the text
Fill: The cell shading or background color. Values are given as hex, in RRGGBB format.
Bold: A Boolean, true or false, which specifies if the text font is bold
Underline: A Boolean, true or false, which specifies if the text font is underlined
StrikeThrough: A Boolean, true or false, which specifies if the text font is strikethrough
An example of this structure is below. This will generate one new table cell and row with the value shown.
{
"Rows": [
{
"Cells": [
{
"Value": "G{{WorkflowId}} -- Inventory Summary (#Items)"
}]
}]
}
A longer example with the values that may be set for cells is below
{
"Rows": [
{
"Cells": [
{
"Value": "Col1Header",
"Bold": true,
"Underline": true,
"StrikeThrough": true
},
{
"Value": "Col2Header",
},
{
"Value": "Col3Header",
}
]
},
{
"Cells": [
{
"Value": "row: 0 colPos: 0",
"Color": "0EBFE9",
"Font": "Arial",
"Fill": "00FF00",
"Bold": true,
"Underline": true,
"StrikeThrough": true
},
{
"Value": "row: 0 colPos: 1"
},
{
"Value": "row: 0 colPos: 2"
}
]
}
]
}
# Word Append to Table
Action Function: The Word Append to Table action will append additional rows of data to an existing table. The target table is specified by its matching ID, which is found in the table properties “Alt Text” value.
Action Outputs:
Successful – The action ran without error
Unsuccessful – there was some issue in the action execution
Action Properties:
Label
This property designates the name of the action or step as shown within the workflow design.
Source file variable
Specifies which file variable contains the document which contains the Table Template ID to use
Target file variable
Specifies the file variable to store the new document with the newly added table. This can be the same variable as the source file variable.
Append Paragraph
This property determines if a Word “Paragraph” should be added after the new table.
Append Page Break
This property determines if a Word “Page Break” should be added after the new table.
Target Table ID
This property specifies which table in the document to append the new data. The ID must match what has been set for the table in the source Word document using the “Alt Text” property for the table.
New Table Data
This property specifies the source JSON document with one or more rows of data to be appended to the newly generated table.
Cell properties available are:
Value: The text for the cell
Color: the color for the cell. Values are given as hex, in RRGGBB format.
Font: The font name for the text
Fill: The cell shading or background color. Values are given as hex, in RRGGBB format.
Bold: A Boolean, true or false, which specifies if the text font is bold
Underline: A Boolean, true or false, which specifies if the text font is underlined
StrikeThrough: A Boolean, true or false, which specifies if the text font is strikethrough
An example of this structure is below. This will generate one new table cell and row with the value shown.
{
"Rows": [
{
"Cells": [
{
"Value": "G{{WorkflowId}} -- Inventory Summary (#Items)"
}]
}]
}
A longer example with the values that may be set for cells is below
{
"Rows": [
{
"Cells": [
{
"Value": "Col1Header",
"Bold": true,
"Underline": true,
"StrikeThrough": true
},
{
"Value": "Col2Header",
},
{
"Value": "Col3Header",
}
]
},
{
"Cells": [
{
"Value": "row: 0 colPos: 0",
"Color": "0EBFE9",
"Font": "Arial",
"Fill": "00FF00",
"Bold": true,
"Underline": true,
"StrikeThrough": true
},
{
"Value": "row: 0 colPos: 1"
},
{
"Value": "row: 0 colPos: 2"
}
]
}
]
}
# Word Delete Table
Action Function: The Word Delete Table removes tables by ID from the Word document. Multiple IDs may be provided by specifying a comma separated list of IDs. Table IDs to remove are specified by matching ID, which is found in the table properties “Alt Text” value. A common use of this action is to remove table templates from a newly generated document.
Action Outputs:
Successful – The action ran without error
Unsuccessful – there was some issue in the action execution
Action Properties:
Label
This property designates the name of the action or step as shown within the workflow design.
Source file variable
Specifies which file variable contains the document which contains the Table Template ID to use
Target file variable
Specifies the file variable to store the new document with the newly added table. This can be the same variable as the source file variable.
Table ID(s) comma separated
One or more comma separated table IDs to remove from the source document.
# Insert HTML into Word
Action Function: The insert HTML into Word action provides options to inject HTML or HTML originated formatted content into a Word document. To inject or insert HTML into a document, the document must be set up with one or more Word "Fields". To create a field in Word, see the Word ribbon bar under "Insert", "Quick Parts", "Field". After inserting a field, select "Field names" as info, and provide a new value which will be the field name to be replaced with HTML by the action.
Note: While potentially very useful, inserting HTML into Word can be a potentially complex effort, as Word is neither a true HTML browser, nor a full replacement for HTML layout. The options required to insert HTML are not particularly obvious, either. As an example, to insert a HTML word table, it is required to use "Preserve as HTML". Experimentation is often required to get the desired results, and often with some limitations.
The action has the follow properties.
Source file variable - specifies the file variable containing the Word document with fields to be replaced with HTML
Target file variable - specifies the target file variable to store the modified document
Fields to replace - This property provides for one or more target fields to be replaced with the specified HTML. The properties are as follows.
Field ID to replace - This is the "ID" of the field to be replaced, see the "Field Properties, New value" in the screen example above
HTML - This is the HTML to be inserted where the Field is located
CSS - This is optional user provided CSS to control the display of the HTML
Force Inline - This will attempt to inject the HTML forcibly inline with the Word material. This option is not compatible with the "Preserve as HTML" option to set to True.
Preserve as HTML - When false, the HTML will be "best effort" converted to Word formatted native document format. When true, the HTML will be inserted as a Word "altChunk" as native HTML.
Action Outputs:
Successful – The action ran without error
Unsuccessful – there was some issue in the action execution
Action Properties:
Label
This property designates the name of the action or step as shown within the workflow design.
Source file variable
# Convert To PDF
Action Function: The Convert To PDF action will convert a provided document to PDF format. The action leverages LibreOffice to perform the conversion. LibreOffice must be installed to each workflow engine instance. Use Libre portable, multi-lingual standard from https://www.libreoffice.org/download/portable-versions/
This action will support many file types including Word, Excel, PowerPoint, HTML, and images.
Once installed, set the proper path to soffice.exe in the action’s XML in the LibrePath node as below
<librepath>C:\Projects\LibreOffice\App\libreoffice\program\soffice.exe</librepath>
NOTE: if you are updating or converting an existing action, please insure the node below is set properly.
<convertmode>Libre</convertmode>
To specify an override temp folder from the system default, use the following node with your path
<DocumentTempPath>c:\temp\</DocumentTempPath>
Action Outputs:
Successful – The action ran without error
Unsuccessful – there was some issue in the action execution
Action Properties:
Label
This property designates the name of the action or step as shown within the workflow design.
Source file variable
The input document to be converted to PDF
Target file variable
The target file variable to store the PDF