Google apps script 列中的单元格编号google应用程序脚本
我所要做的就是设置一个范围,然后对该范围内的单元格进行编号,即B2:B11为1、2、3等Google apps script 列中的单元格编号google应用程序脚本,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我所要做的就是设置一个范围,然后对该范围内的单元格进行编号,即B2:B11为1、2、3等 function numberMe() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var counter = 1; var cell = sheet.getRange("G2:G11"); while(counter <= 10){ cell.setValues(cou
function numberMe() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var counter = 1;
var cell = sheet.getRange("G2:G11");
while(counter <= 10){
cell.setValues(counter);
}
这只是在每个单元格中给出一个像1的数字,而不是1,2,3等等。。。文档中提到了setValues,但这似乎是沿着行而不是沿着列设置值。首先,您没有增加计数器,其次,文档中指出setValues必须与数组一起使用,所有数组都已初始化,作为双数组,并且大小与范围完全相同 因此,你的时间应该是有限的
var cell = sheet.getRange("G2:G11");
var toPaste = [];
while(toPaste.length < cell.getNumRows()){
toPaste.push([counter++]);
}
cell.setValues(toPaste);
谢谢你的答复。我现在收到错误消息:范围高度不正确,为9,但应为10var计数器=0;数组是从零开始的,应该从0开始,而不是从0开始1@ScampMichael是的,我没有看到它被初始化,并假设它是0。我更新了答案,以预见任何初始数字。