Adding a line break using keyword


(Nick Papadatos) #1

Matrix Version: 5.3

Hi talented squiz folk

I have an Asset Listing page with a design => content_type=“text/csv”
Content type - form submission

In the default format I have %question_answer_1706218_q8^replace:,: % . . .
I’m trying to get something similar to a " \n" - linebreak

My aim is to do the following within each cell

From this:
text1,text2,text3,text4

To this:
text1
text2
text3
text4

Thanks
N


(Bart Banda) #2

I think you can do it with the replace keyword modifier and add a regex new line break? Using " \r\n" directly in the keyword modifier or using it via a regex asset.

Then you just have to wrap those in quotes apparently to preserve the new lines according to https://stackoverflow.com/questions/566052/can-you-encode-cr-lf-in-into-csv-files


(Nick Papadatos) #3

Thanks Bart

I tried using:

%question_answer_1706218_q8^replace:(,\r\n):%,%question_answer_1707462_q4%

The above kind of works but places data in odd columns across the spreadsheet. What did you have in mind?
Regards
N


(Bart Banda) #4

Did you try wrapping that in quotes?

"%question_answer_1706218_q8^replace:(,\r\n):%,%question_answer_1707462_q4%"

(Nick Papadatos) #5

Thanks Bart,
That didn’t work either, it’s no big deal really I just thought Matrix was able to add a line break. The client can right click on the cell/column > format cells > Text control: wrap text

Cheers
Nick


(Bart Banda) #6

Well, Matrix can generate any text you want it to really, it’s all about how the CSV reader needs to interpret it, so you just need to match that. Perhaps using just the keyword replace modifier is not enough and you need to use the regex asset to do the proper line replacement in. For example, try hardcoding the text first to figure out exactly what you need for the line break, once that works, then try and replicate it with the keyword.


(Pawel Masloch) #7

Hi Nick,

So, if you list your results in asset listing why don’t you simply format your results using html/css under Type/Default Format? One of a nifty ways is e.g.:

 <pre style=“word-wrap: break-word; white-space: pre-wrap;”… “returned data”, “returned data” …/pre> 
where you can even use column headers for your data. Only, make sure you have your strings wrapped in quotes and leave a white space between data. You can also create and save XML from form submission and then convert it, format it and use data in any way you wish.
Also, bear in mind that encode (e.g.:UTF-8) plays a role in how data is processed and displayed.
Windows line-endings (\r\n) should work well, too - did you try with no comma up front?

(Douglas (@finnatic at @waikato)) #8

If you don’t mind having to use SSJS, you could use the explode modifier to put your source value into an array and then iterate through the array printing out as you require.


(Nick Papadatos) #9

not until we upgrade :slight_smile: