I am able to create folders from an existing list in google sheets. This list keeps growing and I would like for the folders to be created (probably on a time trigger). My problem is that it creates all folders again and that it reruns everything starting from A1... and then there is a problem where it automatically posts the links on B column, and not particularly B1, but sometimes B5, B3...
basically i would like to create folders as the list continues to grow without rerunning everything and place the new hyperlinks in the D column...
I tried using the while function to try to check if the folder has already been created but it doesn't really helped me that much since I end up with an error.
function createAndHyperlink() { var ss, sh, parent, parent2, r, v, thisCell, folder ss = SpreadsheetApp.getActive() sh = ss.getSheetByName('f') parent = DriveApp.getFileById(ss.getId()).getParents().next(); parent2 = DriveApp.getFolderById("1aKKrybi1uSCJPD6m_L5YXOgAV_DofKCK") r = sh.getRange('A1:A') v = r.getValues() for (var i = 0, l = v.length; i < l; i++) { thisCell = sh.getRange(i + 3, 2) if (v[i][0] && !thisCell.getFormula()) { folder = parent2.createFolder(v[i][0]); thisCell.setFormula('=HYPERLINK("' + folder.getUrl() + '"; "' + v[i][0] + '")'); } } }
There is not an error at the end, but it's not orderly, I mean I'm very close to what I need and would really appreciate the help!
Try something Like this:
function createAndHyperlink() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('f');
var parent=DriveApp.getFolderById("1aKKrybi1uSCJPD6m_L5YXOgAV_DofKCK")
var vr=sh.getRange(1,1,sh.getLastRow(),1);//column 1 is values
var v=vr.getValues();
var dr=sh.getRange(1,3,sh.getLastRow(),1);//column 2 is hyperlinks
var d=dr.getValues();
var hr=sh.getRange(1,2,sh.getLastRow(),1);//column 3 is done ... Prevent old assignment from getting recreated
var h=hr.getFormulas();
for(var i=0;i<v.length;i++) {
if(v[i][0] && !h[i][0] && !d[i][0]) {
var folder=parent.createFolder(v[i][0]);
var formula='=HYPERLINK("' + folder.getUrl() + '"; "' + v[i][0] + '")';
h[i][0]=formula;
d[i][0]='Done';
}
}
dr.setValues(d);
hr.setFormulas(h)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.