Skip to main content
Version: 1.28 (Current)

Html to Word (.docx) - Experimental

Audience: Low-code Engineers

Skill Prerequisites: HTML, CSS, Tokens

Converts HTML into a Word document (.docx) and saves it in a portal folder. You can start from a blank document, or from a Word template whose page setup, styles, headers and footers are kept.

Unlike Convert from HTML to Word, this action also applies the CSS rules in <style> blocks, so you can style the document with classes and selectors instead of inline styles only.

caution

This action is experimental. Its behavior may change in future versions. Test the output with your own HTML before you rely on it.

note

This action requires the Word feature (PAAWORD) to be licensed. It's part of the separate PlantAnApp.Word add-on package. If you don't see the action in the Documents group, the add-on isn't installed.

Typical Use Cases​

  • Export a record or report as an editable Word document, styled with a shared <style> block
  • Reuse HTML and CSS you already have, for example from an email or report template, to build a Word file
  • Add generated content to a branded template, for example a letterhead with a company header and footer

Don't use it to​

  • Fill in placeholders in an existing Word layout. Use Replace Tokens in Word Document instead.
  • Create a document that must look exactly like a web page. Word supports only part of what HTML and CSS can do. Use Generate PDF if the output doesn't need to be editable.
  • Read text from a Word document. Use Plain text from Word instead.

How it differs from Convert from HTML to Word​

Both actions produce a .docx file, take the same parameters and create the same output tokens. Both use the open-source Html2OpenXml library, so the HTML elements they support are the same.

Html to Word (.docx) - ExperimentalConvert from HTML to Word
<style> blocksCSS rules are applied to the matching elements before conversion.Ignored. Only inline style attributes are used.
StatusExperimentalObsolete
PackagePlantAnApp.Word add-on, licensed separatelyIncluded in the standard install
Action typePlantAnApp.Word.ConvertFromHTMLToWordHTMLtoWord

Pick this action if you have the Word add-on and want to style the document with CSS classes or selectors. Pick Convert from HTML to Word if you don't have the add-on, or your HTML uses inline styles only.

Action NameDescription
Convert from HTML to WordThe older HTML to Word action, which uses inline styles only.
Replace Tokens in Word DocumentFills in content controls in a Word template.
Plain text from WordReads the text of a Word document into a token.
Generate PDFCreates a PDF from HTML.
Send EmailSends the generated document as an attachment.

Input Parameter Reference​

ParameterDescriptionSupports TokensDefaultRequired
HTMLThe HTML to convert. Headings, paragraphs, text formatting, lists, tables, links and images are supported. CSS rules in <style> blocks are applied. See Styling with CSS. If empty, no content is added.Yesempty stringNo
Template File IdentifierOptional. A .docx file to use as the starting document, as a file ID or a path relative to the portal root. For example, if the file is Portals/0/Templates/Letterhead.docx, enter Templates/Letterhead.docx. The HTML is added to the end of the template's body. Leave empty to start with a blank document.Yesempty stringNo
FolderThe folder to save the document in. Select a folder, or in expression mode enter a folder path relative to the portal root, for example Images/ExampleFolder, which is saved in Portals/<PortalID>/Images/ExampleFolder. The folder is created if it doesn't exist. If empty, the document is saved in the Temp folder.Yesnone selectedYes
PatternThe name for the document, without the extension, for example generated-document-[User:Username]. .docx is always added. Leave empty to use a random name.Yesempty stringNo
Handle DuplicatesWhat happens if a file with the same name already exists in the folder. Rename saves the new document with a unique suffix added to its name. Overwrite replaces the existing file.NoRenameNo

Output Parameters Reference​

ParameterDescription
Output Token NameOptional. The name of the token that stores details of the new document. See the tokens in the next table.

If Output Token Name is WordDoc, the following tokens are created. [WordDoc] on its own isn't set, so always use a property.

TokenDescription
[WordDoc:FileId]The document's file ID.
[WordDoc:FileName]The file name without the extension.
[WordDoc:FileNameAndExtension]The file name with the extension.
[WordDoc:FileExtension]docx.
[WordDoc:RelativeUrl]The URL relative to the site root.
[WordDoc:AbsoluteUrl]The absolute URL.
[WordDoc:FilePath]The physical path on the server.
[WordDoc:FolderId]The ID of the folder that contains the document.
[WordDoc:FolderPath]The path of the folder that contains the document.
[WordDoc:FileSize]The file size. FileSizeB, FileSizeKB, FileSizeMB and FileSizeGB give the size in a specific unit.
[WordDoc:MimeType]The MIME type.
[WordDoc:Base64]The file contents as a Base64 string.
[WordDoc:Stream]The file contents as a stream, for example to save into a database.
[WordDoc:LinkClick]Obsolete. Use RelativeUrl or AbsoluteUrl instead.

Styling with CSS​

Before the HTML is converted, each rule in each <style> block is applied to the elements that match its selector, and the <style> blocks are removed. The rule's declarations are written into the element's style attribute.

Keep these limits in mind:

  • The rule replaces the element's inline style. If an element has style="color: red" and also matches a <style> rule, only the rule's declarations are kept.
  • Rules don't combine. If several rules match the same element, the last matching rule wins and the others are dropped. For example, with p { font-size: 11pt } followed by .note { color: gray }, a <p class="note"> gets only color: gray.
  • Only plain style rules are applied. Rules inside @media or other at-rules are ignored.
  • After the styles are applied, Html2OpenXml decides which CSS properties Word can show. Complex layouts, such as flexbox or grid, aren't converted.

To style an element with several properties, put them all in one rule, or give the element a single class that holds everything it needs.

Considerations​

  • Test with real content. The action is experimental, so check the output in Word, especially tables and images.
  • Images. Relative image paths are resolved against the portal's home folder. Absolute https:// URLs are downloaded when the document is generated.
  • Update fields prompt. When a template is used, the document is set to update its fields when it's opened, so tables of contents in the template are refreshed. Word asks the user to confirm this when the document is opened.
  • Folder IDs. Use a folder path in Folder rather than a folder ID.
  • The template must have the .docx extension, otherwise the action fails.
  • License. If the Word feature isn't licensed, the action can't run. See the note at the top of this page.

Examples​

tip

To understand how to use the below examples, please see Running Examples.

1. Create a styled Word document from HTML​

This action converts an HTML summary with a <style> block into Exports/summary-<Username>.docx. The heading, table header and total row are styled by the CSS rules. The document's details are stored in the WordDoc token, for example [WordDoc:AbsoluteUrl].

{
"Title": "Html to Word (.docx) - Experimental",
"ActionType": "PlantAnApp.Word.ConvertFromHTMLToWord",
"Description": "Build the styled summary document",
"Condition": null,
"Parameters": {
"HTML": "<style>\n h1 { color: #1F4E79; font-family: Arial; }\n th { background-color: #1F4E79; color: #FFFFFF; }\n .total { font-weight: bold; }\n</style>\n<h1>Account summary</h1>\n<p>Prepared for [User:DisplayName].</p>\n<table border=\"1\">\n <tr><th>Item</th><th>Value</th></tr>\n <tr><td>Email</td><td>[User:Email]</td></tr>\n <tr class=\"total\"><td>Status</td><td>Active</td></tr>\n</table>",
"TemplateFileIdentifier": "",
"Folder": {
"Expression": "Exports",
"Value": "",
"IsExpression": true,
"Parameters": {}
},
"Pattern": "summary-[User:Username]",
"Duplicates": {
"Expression": "",
"Value": "Overwrite",
"IsExpression": false,
"Parameters": {}
},
"OutputTokenName": "WordDoc"
}
}

Revised 09/26/2026