I am using this script to generate json based on my spreadsheet.
Some of my cells have a new line that no visible within a cell.
When I fun a script the new line appears like ..mytext \nMytext
, etc
I want to replace \n
with <br>
, so I placed that at line 44
text.replace('\n', "<br>")
which is didn't work at all, so I've changed it to that:
text.replace(/\n/g, "<br>");
which didn't work either, the \n
is still present within an output.
I believe it has a different code or something, any ideas how to fix?
The text to google sheet is copy-pasted from google docs
CodePudding user response:
From text.replace(/\n/g, "<br>");
and which didn't work either, the \n is still present within an output.
, in this case, how about the following modification?
From:
text.replace(/\n/g, "<br>");
To:
text.replace(/\\n/g, "<br>")
From
I want to replace \n with <br>, so I placed that at [line 44](https://gist.github.com/florentdescroix/9513cfd957f8b2cde7b832cf7170c84a#file-exportjson-js-L44)
, how about the following modification?var output = HtmlService.createHtmlOutput("<textarea style='width:100%;' rows='20'>" text.replace(/\\n/g, "<br>") "</textarea>");
When I saw your showing script, at
makeJSON_
,var jsonString = JSON.stringify(object, null, 4);
is returned. By this, I thought thattext.replace(/\n/g, "<br>")
is required to be modified totext.replace(/\\n/g, "<br>")
.