New line character breaks ouput csv

I use builder with js components:
My experiment displays text snippets from a conditions file (textbox with var from condition file). These snippets might contain line breaks, which seems to be a major problem for psychojs (?).
If I use “real” line breaks in the conditions xlsx (as in [alt]+[return]) the output csv from pavlovia breaks, since it interprets those line breaks as delimiter. If instead I use escaped new lines (as in \n) they will not be displayed as new lines online. The text just reads “First line\nSecond line” (same goes for <br>). I tried putting quotation marks into the conditions xlsx an trimming them off in js - but that doesn’t resolve it either.

Offline it works just fine (the line break does not break the csv).
Is there anything I can do to fix my output files?

I found this thread on the forums:

Online experiment saved data was format misplacement - Online experiments - PsychoPy

But theres no answer to the question : (

What are you using to open the CSV file? In principle these line breaks should work.

Alternatively try \\n or try text_1.text=conditionsColumn

1 Like

MS Excel - but I’m installing Libreoffice at the moment to make sure.
I tried putting \\n into the conditions file but that won’t display as line break either.
For the last one: Do you mean creating the text-component entirely in js? Or just setting the text?

Another option could be to somehow disable the logging for the xlsx conditionColumn. But I did not find a way to do so.

// edit: ok so it really is just ms excel. In libreoffice everything is displayed correctly. Which is really weird, because quotation marks are set as text qualifier. But okay then.
Big thank you btw! You’re doing a fantastic job on the forums and your posts already helped like a million times.

Okay, so just a small update, because I know that the people using my experiment will probably use ms excel:

I now use “\n” in the input xlsx for line breaks and do some stupid regex replace at the beginning of that routine to “un-escape” the escaped escape-char for new line:

tmp_regex = /\\n/g;
tmp_str = question.replace(tmp_regex, "\n");
textbox.setText(tmp_str);

where question is the variable from my input xlsx and textbox my TextBox component. You might need to refresh the component with textbox.refresh();
This is compatible with excel and does display the line breaks correctly.

1 Like