问题描述
有没有办法让我不需要手动输入数字?
谢谢。
解决方法
您可以使用Apps脚本Custom Function来做到这一点。
首先,通过选择工具>脚本编辑器打开绑定的脚本,然后将以下函数复制到脚本中:
function MIRROR(until) {
const sheet = SpreadsheetApp.getActive().getSheetByName("Question");
const lastRow = getLastDataRow(sheet);
const values = sheet.getRange(1,1,lastRow).getValues();
let series = values.slice(0,4);
let output = [];
let currentNumber = values[values.length - 2][0] + 1;
if (!until) currentNumber;
for (; currentNumber <= until; currentNumber++) {
output.push([[currentNumber],[series[1][0]],[""],[""]]);
}
return output.flat();
}
function getLastDataRow(sheet) { // Get last row in column A (see https://stackoverflow.com/a/53587462)
var lastRow = sheet.getLastRow();
var range = sheet.getRange("A" + lastRow);
if (range.getValue() !== "") {
return lastRow;
} else {
return range.getNextDataCell(SpreadsheetApp.Direction.UP).getRow();
}
}
一旦定义,就可以使用功能MIRROR
,就像使用任何工作表内置功能一样。该函数将接受一个参数,您可以在该参数中指定该序列号,直到该序列继续为止。例如,参见: