我正在尝试编写一个Google表格脚本:
我是一个完全的初学者,只是设法走得这么远:
function UpdateDrawDownToAvailable() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange("LF11:LI11");
range.clearContent();
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange("LF8:LI8").copyTo(sheet.getRange("LF11:LI11"), {contentsOnly:true});
}
非常感谢任何帮助!
答案 0 :(得分:1)
代码可能看起来像这样。我还没有测试过它。请注意Logger.log('myVariableName: ' + myVariableName);
语句。要查看Logger.log()
语句中的打印输出,请使用"查看"菜单,然后选择" Logs"菜单项。
function UpdateDrawDownToAvailable() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var rangeForRow11 = sheet.getRange("LF11:LI11");
var row11_Values = rangeForRow11.getValues(); //A 2 Dimensional array of values.
row11_Values = row11_Values.join().split(","); //One dimension array of values
Logger.log('row11_Values: ' + row11_Values);
var rangeForRow8 = sheet.getRange("LF8:LI8");
var row8_Values = rangeForRow8.getValues(); //A 2 Dimensional array of values.
row8_Values = row8_Values.join().split(","); //One dimension array of values
Logger.log('row8_Values: ' + row8_Values);
var i=0,
thisLoopCellValue = "",
row8Value="";
for (i=0;i<row11_Values.length;i+=1) { //Loop the number of times that the array is long
thisLoopCellValue = row11_Values[i];
Logger.log('thisLoopCellValue: ' + thisLoopCellValue);
if (thisLoopCellValue === "Forecast") {
sheet.getRange(11, 325+(i+1)).clear(); //Clear the cell
SpreadsheetApp.flush(); //Apply all pending changes
//Get row 8 value
row8Value = row8_Values[i];
Logger.log('row8Value: ' + row8Value);
sheet.getRange(11, 325+(i+1)).setValue(row8Value);//Put row 8 value into row 11
} else { //If this cell value does not equal to "Forecast"
return; //Quit
};
};
};