我需要改变我的匹配功能,匹配单独工作表上的两列并返回一个 匹配到第三张纸,以便它返回匹配的行
我一直在努力,我的头在旋转,没有成功
由于
function RunMatch() {
// 0 is the LookIn sht column # to match on
// 1 is the LookWith sht column # to match on
MatchCols("LookInSheet","LookWithSheet","PostbackSheet",0,1)
}
function MatchCols(sShtName,tShtName,pbShtName,matchIn, matchWith){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var LookInSht = ss.getSheetByName(sShtName);
var LookWithSht = ss.getSheetByName(tShtName);
var PBSheet = ss.getSheetByName(pbShtName);
var LookIn = LookInSht.getDataRange().getValues();
var LookWith = LookWithSht.getDataRange().getValues();
var list = [];
for (i in LookIn){
var curName = LookIn[i][matchColIn];
var exists = true;
for (j in LookWith){
var curCheck = LookWith[j][matchColWith];
if (curCheck == curName){
exists = false;
break;
};
}; // end for j
list.push([exists ? "" : curName]);
} // end for i
PBSheet.getRange(1, PBSheet.getLastColumn() +1, list.length, 1).setValues(list);
}
答案 0 :(得分:0)
如果我理解正确,当PostbackSheet
LookIn
列matchColIn
列中的值LookIn
时,您希望matchColWith
包含LookWith
的整行1}} exists
列。
不要使用list
,只需在找到匹配项时将行添加到if (curCheck == curName){
list.push(LookIn[i]);
break;
}
:
PBSheet
然后,当您写入PBSheet.getRange(1, PBSheet.getLastColumn() +1, list.length, list[0].length).setValues(list);
时,请使用列表大小以确保范围是正确的大小:
var AddButton = document.createElement("button");
var AddString = "add";
var SectorString = "1_1";
AddButton.setAttribute("onclick",'AddOrDeleteDiv(' + JSON.stringify(AddString) + ',' + JSON.stringify(SectorString) + ')');
function AddOrDeleteDiv(addStr, secStr) {
//code
}