Using Word connectors from Power Automate to create documents|Replacing text, adding dynamic items and creating PDFs.

The Word connector action gives the impression that it is not used very often because it requires a premium licence.

I happened to have a chance to use these Word actions this time, so I took notes on how to use them.

スポンサーリンク

Word Online connector and each action.

There are currently two actions available for the Word Online connector here, both of which require a paid licence.

In this case, we will use these two actions to create an invoice in Word format in Power Automate and convert the invoice to PDF.

Create template files in the Word desktop application.

In this case, the template will be created using this Word file in invoice format.

Advance preparation: Display the [Development] tab in the Word desktop application.

First, open the Word desktop application, select [Options] from [File],
then check [Development] from [Ribbon User Preferences].
If the [Development] tab appears, you are ready to go.

Set where to replace text.

The first step is to set up the Word template where the text is to be replaced (e.g. company name, total amount, etc.).

Navigate to the location where you want to replace the text (‘Company name’ in the image) and select Text content controls.
If you do so, the display will look like the image below,
so delete ‘Click here~~’ and enter a name that is easy to understand (in this case, ‘Business partner name’).
Set this to all the strings for which you want to replace the text, and the replacement point setting is complete.

Set where items are dynamically added.

The next step is to set where the items are dynamically added (in this case, the billing items).
First, set a [Text Content Control] for each cell as before.
Then select the row as shown in the image, click Section Content Repeat Control,
and when the entire row is enclosed, press Properties, set any title and tags and press OK.

This completes the creation of the Word template.

This Word template file is used to create invoices in Power Automate and convert them to PDF.

As of 30 Mar 2024:
After setting up this [Section Content Repeat Control], editing/deleting the [Text Content Control] inside may cause anomalies in the Word content produced when Power Automate is run.

If the final generated Word content is messed up, deleting everything once, including the [Section Content Repeat Control], and then recreating it may (sometimes) work.

Creating invoices with Power Automate.

Replacing text

First, save the template you have just created to any location in the cloud (in this case, OneDrive) and select that location under ‘Preconfigure Microsoft Word template’.
Then, as shown in the image, the text replacement points you have just set up will be displayed, and you can insert the text you want to insert into the invoice.
The text is fixed this time, but you can of course also retrieve it from SharePoint or other sources.
Pass the content created by this action to the [Create File] action and so on, and the creation of the flow is complete.
When executed, the invoice is created as shown in the image.

Adding dynamic items

Then add the invoice items dynamically.
*The case is that you have a SharePoint list like this and you want to add these items to the invoice.
Press the icon in the top right corner of the item that specifies [Section Content repeat control] in the Word action, so that the ID corresponding to each item is displayed,
Combine this ID with [Get multiple items] and [Array variable] to create the array data corresponding to the Word template you have created.
*If sequential numbers are not required, they can be created in actions such as ‘Data manipulation’.
Set the array data you have created and you are ready to go.
When executed, the items are added dynamically as follows.

Convert created Word invoices to PDF.

The [Convert Word document to PDF] action is then used to convert the created invoice to PDF.

Set the path of the Word file created in the [Create File] action to this action,
Use the [Create File] action again to specify the file content created in the Convert to PDF action to complete the creation of the flow.
When the flow is executed, an invoice can be created in PDF as follows.

Not often used because it requires a paid licence, but very useful if you want to create PDF documents.

Related articles.

タイトルとURLをコピーしました