我有三列数据
selector label option list
time you personally have been engaged with uscan label_1 Arts
time you personally have been engaged with uscan label_2 Children’s Issues
time you personally have been engaged with uscan label_3 Coaching
time you personally have been engaged with uscan label_4 Community Development
time you personally have been engaged with uscan label_5 Conflict
time you personally have been engaged with uscan label_6 Consulting
我正在尝试连接这些列,以便在第4列中得到
option {
label: "Label_1;
selector: ["time you personally have been engaged with uscan"="Arts"];
}
option {
label: "Label_2;
selector: ["time you personally have been engaged with uscan"="Children’s Issues"];
}
etc
我的尝试
result[i] = [""option {label:""" + values[i][0] + "";" + "selector: [" + values[i][0] + ""=" + + values[i][1] + ""];}"];
被所有必需的单引号玷污
谢谢
GS
function OptionsList() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("OptionList");
var lr = sheet.getLastRow();
var values = sheet.getRange(2, 1, lr,3).getValues();
var result = [];
//Add items to results
for(var i=0; i<lr; i++){
result[i] = [""option {label:""" + values[i][0] + "";" + "selector: [" + values[i][0] + ""=" + + values[i][1] + ""];}"];
}
//Post back to column 4 starting on row 2
sheet.getRange(2, 4, lr, 1).setValues(result);
}
答案 0 :(得分:1)
这次修改怎么样?
result[i]
"
已转发为\"
。\n
。filter()
删除空单元格。function OptionsList() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("OptionList");
var lr = sheet.getLastRow();
var values = sheet.getRange(2, 1, lr, 3).getValues();
values = values.filter(function(e){return e[0] && e[1] && e[2]}); // Added
var result = [];
//Add items to results
for(var i=0; i<values.length; i++){ // Modified
result[i] = ["option {\nlabel: \"" + values[i][1] + ";\n" + "selector: [\"" + values[i][0] + "\"=\"" + values[i][2] + "\"];\n}"]; // Modified
}
//Post back to column 4 starting on row 2
sheet.getRange(2, 4, result.length, 1).setValues(result); // Modified
}
"
"Label_1
之后需要label: "Label_1;
吗?如果需要,请修改如下。
+ values[i][1] + "\";\n"
如果我误解了你的问题,请告诉我。我想修改它。