如何在google-apps-script中包含K列!= null条件? [英] How to include Column K != null condition in google-apps-script?
本文介绍了如何在google-apps-script中包含K列!= null条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个代码,可以在每次运行时将数据从一张纸粘贴粘贴到另一张工作簿.但是,我只希望从K列不为null的原始工作表中复制特定数据.有人可以帮忙推荐一下如何将其合并到我的代码中吗?
I have a code that copy pastes data from one sheet to another workbook whenever I run it. However, I only want specific data to copy from the original sheet where column K is not null. Could someone help recommend how I can incorporate that in my code?
提前谢谢!
function transferList()
{
var sourceSheet =
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Colombo");
var sourceData = sourceSheet.getDataRange().getValues();
sourceData.splice(0,1); // Remove header
var targetSS = .
SpreadsheetApp.openById("TargetSheetID").getSheetByName("Tester");
var targetRangeTop = targetSS.getLastRow(); // Get # rows currently in target
targetSS.getRange(targetRangeTop+1,1,sourceData.length,sourceData[0].length).setValues(sourceData);
}
推荐答案
您可以遍历数据并将所有具有非空列K的值放入另一个数组:
You could iterate through your data and put all the values the have non-null column K into another array:
var targetData = [];
for (var i in sourceData) {
if (sourceData[i][11] !== null && sourceData[i][11] !== '') {
targetData.push(sourceData[i]);
}
}
然后将targetData
粘贴到目标表中.
Then you'd paste targetData
into your target sheet.
这篇关于如何在google-apps-script中包含K列!= null条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文