Skip to main content
Solved

[FME 2025] How write .docx files to html pages

  • July 1, 2026
  • 2 replies
  • 43 views

joy
Enthusiast
Forum|alt.badge.img+15

Hello everyone,

The funny thing is, I am trying to read .docx files which apparently I have never done until now in FME Form I am trying to convert several .docx files to html pages.

I tried reading the help page of the Word reader, but unfortunately I don't get much wiser. It says to use the Word reader in conjunction with the transformer MSWordStyler. I looked into the MSWordStyler, but I also don't get much wiser. When I just connect a word reader with a html writer, I don't get any output (which I kind of expected). However, I really have no clue how to get from .docx → html

If I import all docx files in FME form, I kind of get a mess of all word pages meshed together in the Data Inspector

 

Best answer by j.botterill

What the Word Reader actually does is read the document into FME's rich text model, preserving things like: Paragraphs, Headings, Lists, Tables, Formatting runs and Images (optionally)

The MSWordStyler is what converts FME's internal Word formatting into HTML/CSS styling attributes that the HTML writer can understand.The transformer generates HTML fragments from the Word formatting information but it probably does it poorly !

The trick would be to inspect all the Format attributes…and organise these into appropriate html_content parts. Even write out a CSV to start with prior to trying html writer

Another option is to use PythonCaller and a library that has library smarts built in. e.g. mammoth


import mammoth

with open(docx_path, "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)

html = result.value

 

2 replies

j.botterill
Evangelist
Forum|alt.badge.img+61
  • Evangelist
  • Best Answer
  • July 1, 2026

What the Word Reader actually does is read the document into FME's rich text model, preserving things like: Paragraphs, Headings, Lists, Tables, Formatting runs and Images (optionally)

The MSWordStyler is what converts FME's internal Word formatting into HTML/CSS styling attributes that the HTML writer can understand.The transformer generates HTML fragments from the Word formatting information but it probably does it poorly !

The trick would be to inspect all the Format attributes…and organise these into appropriate html_content parts. Even write out a CSV to start with prior to trying html writer

Another option is to use PythonCaller and a library that has library smarts built in. e.g. mammoth


import mammoth

with open(docx_path, "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)

html = result.value

 


joy
Enthusiast
Forum|alt.badge.img+15
  • Author
  • Enthusiast
  • July 2, 2026

@j.botterill I used the mammoth library and this made everthing very easy. With help of AI I got the following code that worked. I got the path_windows from the Directory and File Pathnames Reader

import os
import mammoth

class FeatureProcessor(object):

def input(self, feature):

docx_path = feature.getAttribute('path_windows')

with open(docx_path, "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)
html = result.value

html = f"""<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
{html}
</body>
</html>
"""


# Bestandsnaam zonder extensie
file_name = os.path.splitext(os.path.basename(docx_path))[0]

# Doelmap
output_folder = r"C:\deletedforsafetyreasons\HTML"

# Volledig pad naar html-bestand
html_path = os.path.join(output_folder, file_name + ".html")
#belangrijk om utf-8-sig aan te geven ipv utf8 anders worden niet de hele html body getoond
with open(html_path, "w", encoding="utf-8-sig") as html_file:
html_file.write(html)

feature.setAttribute("html_path", html_path)

self.pyoutput(feature)