Line breaks and paragraphs in Microsoft Word Template

Hello there, I want to add text paragraphs with line breaks in the microsoft word template module.

In the help doc for word templates it says: “The Microsoft Word Templates app accepts only single-line plain text for replacement values. When adding line breaks, they will be viewed as spaces and won’t affect the formatting of the text.” (https://www.make.com/en/help/app/microsoft-word-templates)

Is there any workaround or way to still get in text paragraphs with line breaks? I desperately need this function. Thank you!

Hiya @Malte; given the documentation says simple text only, and line breaks are converted, there’s no getting what you want cleanly.

One idea is to pass newline characters like /n as {NEWLINE} and then run a script on the template to replace {NEWLINE} with the desired line break.

However, that involves further scripting within the Microsoft ecosystem, similar to Google AppScript.

Hello @Malte and welcome to the Make Community!

Is there any possible way to add more tags and separate them by spaces in the template?

Hi Donald, sadly there is no other option as we get the full text with paragraphs from a software with no option of splitting the text

@Malte have you solved this? I need this as well

This is the exact problem I am facing with. I tried splitting and aggregating the original plain text in many ways, I also transformed it into different formats (rich text, markdown, HTTP, unicode), with zero result.

Does anyone found a workaround for this?

none, I have ask on Microsoft word api forums and got nothing.

@Malte, @Ivy_Saskia and @Janos,

Another thought about this, why not try making your template in Google Docs then downloading the file as DOCX? If DOCX isn’t the final format, then download as PDF is another option.

The final document might look a little different than what Word would produce, but it is something to consider!

Hi Donald, I thought about it, and it would make sense when personal use. The issue comes when the client is a company that runs all its data in a Microsoft environment. They won’t change the whole ecosystem for the sake just one bot.

Btw I found a some sort of ‘workaround’. I insert the plain text in a MS Excel Workbook because (in contrary to Word) there are many Excel modules in Make. The formatting stays intact when putting a long text in a cell, although it’s not very handy if you want to edit the text later.

Dear Make Dev team: do us more Word modules pleeeease!

I’ve got another thought but will test it out first and let you know details and how it goes.

1 Like

Seems what you found is about as good as it gets.

Here’s the best I could come up with so far, not sure if it would help yours or anyone else’s situations.

Here’s an example of my source text, the stuff I want plugged in to the template.
image

The tag list is a list of tags that should always be in my template document.
The Fixed Text is the text I wish to split up and put into my final document. Each line corresponds to each tag in the list, in order. Consecutive new lines count as a single new line so Fixed Text is effectively 4 lines.

Dynamic Text is multi-line and the number of lines may vary, but same thing, it’s effectively 4 lines.

My template file looks like this:

Final document looks like this:

You can see that since I only had effectively 4 lines of dynamic body text, only those 4 lines shows up in the document.

This only works if you have access to modify the template.
You’d have to place line break between multiple conditional tags.
To make it easier, they need to be named such that only a sequential number can make them unique (#hasLine1, #hasLine2, etc…)

The other caveat is that the lines that did not get filled show up as blank lines in the document, so basically just the conditional placeholders were replaced with nothing, but the newline remains in place.

Thank you Donald for taking the time to deal with this, it’s an interesting approach. Let’s say I have an LLM generated blog post or news article. How could I split it up to fixed/dynamic fields when each text has different structure?

@Donald_Mitchell I already tried creating a google doc and then converting it to a word doc, but there are quite a few problems with the conversion and layout. For example the automatic formatting of the table of contents doesn’t work after the conversion.

Yea typical when trying to create Word docs from Google Docs. Works out for many less complex documents, sorry not in your case though :frowning:

Hey @Janos,

Do you have a couple example of different types of output?

The main issue here is that Microsoft’s Graph API doesn’t seem to offer any way to produce Word documents using API.

If you look at a DOCX file, it’s just a zip file containing several XML and other files that describe how to render the document.

Each block of text is represented by a new tag in the document.xml contained within the DOCX archive. Line breaks and other special characters are separate tags.

I’m not positive about how Make does it, but it appears Make it somehow constructing these files and not actually using any API. This would explain why it’s so limited and can’t do much more than just replace text.

Your best bet here is probably hosting your own API that can use something like Python and the python-docx library to build and upload documents according to instructions you provide via API calls from Make to your own server.

You can try this out in Make:

  • Download a DOCX file
  • Use Archive App to Extract Archive
  • Find the bundle that contains document.xml
  • Turn document.xml into text XML, parse it out, find the text you want to replace
  • Use Archive App to Create Archive with the same directory structure and your new document.xml
  • Try to open your new file as DOCX

I currently trying to master the same challenge. Has anyone achieved anything by using the value type “loop or section”?

image

Just tried this out and noticed that if you specify the section (in this case, “#lines”) like this:
image

The newline after “line” gets duplicated when using the Loop or section as value type.
So the result of splitting a bunch of text by newline is this:

image

This actually seems to the best result so far, just confusing to get it working correctly.

1 Like