我正在编写一个脚本,用于将所选行从一个电子表格复制到另一个电子表格,从A列复制到D列。
很好。
问题是3:
const input = [{
"MAINID": "INAP1650001",
"Status": "Approved"
},
{
"MAINID": "INAP1650002",
"Status": "Pending"
},
{
"MAINID": "INAP1650003",
"Status": "Approved"
},
{
"MAINID": "INAP1650004",
"Status": "Pending"
},
{
"MAINID": "INAP1650005",
"Status": "Approved"
}
];
const result = input.reduce((acc, cur) => (cur.Status === 'Approved' ? [ ...acc, cur.MAINID] : acc), []);
console.log(result);
。谢谢。
Sent
答案 0 :(得分:2)
请查看getRange的参数:
替换
var data = sourceSheet.getRange(last, 1, 1, 4).getValues();
使用
var data = sourceSheet.getRange(last, 3, 1, 3).getValues();
您可以使用getHeight查找选定的行数并将其传递给getRange
:
var height = sourceSheet.getActiveRange().getHeight();
var data = sourceSheet.getRange(last, 3, height, 3).getValues();
您可以将所选行的H列的值设置为Sent
:
sourceSheet.getRange(last, 8, height).setValue('Sent');
function main() {
transfer("....", "Foglio1", "Foglio1");
}
function transfer(targetId, sourceSheetName, targetSheetName) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sourceSheet = ss.getSheetByName(sourceSheetName);
var last = sourceSheet.getActiveRange().getRow();
var height = sourceSheet.getActiveRange().getHeight();
var data = sourceSheet.getRange(last, 3, height, 3).getValues();
// copy data
var ss2 = SpreadsheetApp.openById(targetId);
var targetSheet = ss2.getSheetByName(targetSheetName);
//get last row
var lastRow = targetSheet.getLastRow();
//write data
targetSheet.getRange(lastRow + 1, 3, data.length, data[0].length)
.setValues(data);
sourceSheet.getRange(last, 8, height).setValue('Sent');
}