Importing paragraphs into Word

I have a scenario which grades student work via ChatGPT (extremely well!) and gives great feedback including a model answer based on their work, but improved. I am exporting the feedback as a Word document which I email to the student.
The entire thing works except that long text, such as the model answer, doesn’t break into paragraphs in Word. I can see that the paragraph information is imported into the “Fill out a document” module as “\n” but paragraphing is lost. ChatGPT suggested that I use this code for the line breaks but it didn’t do anything:
{{replace(22.FormattedModelAnswer; “\n”; “\n”)}} (that is replacing a double-backslash with a single, but the double-backslash is being changed here into a single too!)

Any ideas?

Hey Graham,

I think Word uses \r for new line instead of \n, try that instead.

Thanks very much for your thoughts, Stoyan.
I tried that and it didn’t work, but I have now tested more possibilities and revealed two problems:

  1. The REPLACE function doesn’t seem to replace non-printing characters. I can see the \n in the input file to the Set Variables module where I am trying to use REPLACE to force the paragraph break. But I can’t even replace it with “hello”. (Although I can replace “the” with “hello”.) I tried to replace both [backslash]n and [backslash][backslash]n
  2. I tried using the REPLACE function to replace “the” with a line break. I tried \n \r \l and \p (single- and double-backslash) but they simply showed up as text in the Word document. No line break.

So in short, I need to know how to replace \n in a variable and I need to know what to replace it with to produce a line/paragraph break in MS Word.

Sorry are you using a template to create the document? There is an entire discussion here regarding the newline issue with several suggestions on workarounds.

Yes I am using a Microsoft Word Template.
Thank you very much again for your response.
I’ve just spent a few minutes looking at that thread and the news isn’t great. As you say, Stoyan, it’s workarounds.
One suggestion is to move the data into a Google Docs document. From there you could presumably use the “Create a document from a template” module. One issue for that for me is that I work in education in the EU where we have GDPR regulations; I don’t know if Google Docs will move my data outside the EU. Also I would be using my private Google account for work. [Out of curiosity I just tried this and it worked immediately, and exactly how the Microsoft Word module should. The line breaks were automatically recognised. But it seems to be difficult to mix Google and Microsoft - Google will only read from and write to Google Drive. I’m having to upload the resulting file there, to then convert it to .docx. OneDrive’s Upload a file module can then take the docx and upload it to OneDrive. It does work.]

Another suggestion is to move the data into Excel. It must then be possible (but not elegant) to use some Excel text functions to split the text into different cells at the line breaks, and then use an Excel Retrieve Data module to read each of these cells into different paragraphs of the Word document. You’d need to create sufficient paragraph variables to deal with the longest possible text you might encounter or there will be truncation, and presumably all these paragraph variables that are empty will result in empty lines in the final outputted Word document.

There is a third suggestion by Donald_Mitchell to do with fixed and dynamic text, but to be honest, I don’t understand it!

Very frustrating. Separating long text at paragraphs in Word seems like quite an obvious requirement. As someone in the other thread said, we need more Microsoft Word modules!