Open andyli opened 4 years ago
Linebreaks are treated as whitespace characters in JavaScript, so they would be trimmed off when the array is parsed. This is done to avoid unintended whitespace at the beginning and end of a string in an array, so unfortunately whitespace characters cannot really be used here.
Would you be alright with commas followed by newlines? For example:
Name | URLs |
---|---|
TestA | www.google.com |
TestB | www.google.com, www.wikipedia.com |
This would allow you to have vertical alignment with your URLs for aesthetic purposes and Google Sheets supports entering new lines in cells by pressing ctrl
+ return
while editing.
I don't understand. Shouldn't it be as simple as cellContent.split(separator).map(line => line.trim())
?
e.g.
var cellContent = " asd \n aasdf";
var separator = "\n";
cellContent.split(separator).map(line => line.trim()); // ["asd", "aasdf"]
Sorry for the slow response. That is actually how arrays are separated, splitting the cell's contents based on a target char value. Whitespace chars do still have their own problems however, including things like false empty strings if two newline chars are used in a row (minor) and how the user inputs desired whitespace chars (intermediate).
Supporting whitespace chars would probably lead to supporting unicode chars, or at the very least would require adding a dropdown to allow convenient selection of the desired char. The main difficulty here arises from the difference between the string "\n" and the char \n
and how users can input the newline char as their separator char.
In any case, this is definitely something that can be added, but I'll need to think about the best way to allow users to select special characters as separator characters. For now, I'd recommend the above solution of using commas followed by newlines to achieve a similar effect.
I would like to use linebreaks as Array separator character for a cell containing URLs since it display more nicely in Google sheets.
I tried but I cannot figure out a way to enter a linebreak in the "Array separator character" field in Export Sheet Data setting penal.