I have multiple links to Google Drive files in an array. I need to get the links into this format in the cell:
File 1, File 2, File 3
The links should be "File 1", "File 2" and "File 3".
The number of links is not the same in each row and I can't figure out is how to dynamically add the correct number of links. The links are coming from Google Form submissions. This is what I have:
var fileList = ["www.link1.com", "www.link2.com", "www.link3.com"];
var richText = "";
for (l = 0; l < fileList.length; l++) {
if (l == 0) {
var text = "File " + l;
var newRichText = SpreadsheetApp.newRichTextValue()
.setText(text)
.setLinkUrl(0, text.length, fileList[l])
.build();
} else {
var text = ", File " + l;
var newRichText = SpreadsheetApp.newRichTextValue()
.setText(text)
.setLinkUrl(richText.length+2, text.length, fileList[l])
.build();
}
richText = richText + newRichText;
Also tried for loops in the middle of the RichTextValueBuilder
thing and there's also a copy()
thing but neither worked for me. Those bits of code were gone hours ago so I can't post them here.
I'm not really that good at JS so it's possible I'm making a basic mistake.