gpt4 book ai didi

javascript - Google 表格将所有工作表上的列与同一列进行比较

转载 作者:太空宇宙 更新时间:2023-11-04 15:59:04 26 4
gpt4 key购买 nike

    function setStrikeThru(range) {
var ss = SpreadsheetApp.getActiveSpreadsheet;
var sheet = SpreadsheetApp.getActiveSheet();
var cell = sheet.getRange(range);
cell.setFontLine("line-through");
}
//
function compareTwo() {
// strike through duplicates on user pages
//if on here
var sheetNameToWatch1 = "WEEKLY COMPLETED JOBS";
//or here
var sheetNameToWatch2 = "PAST JOBS";
//strikethrough here
var shtNames = ["0","Adia","Alejandra","Austin","Daniel","David L"];
//loop through number of values in array
for(var j=1; j < shtNames.length; j++){
var ss = SpreadsheetApp.getActiveSpreadsheet();
//use this sheet as values to check for
var sheet = ss.getSheetByName(sheetNameToWatch1);
//strike through on this sheet
var targetSheet = ss.getSheetByName(shtNames);
//count number of rows to check
var totalRows = sheet.getRange(targetSheet.getLastRow() + 1, 1);
//loop through number of rows
for (var i = 1; i < totalRows; i++){
var cell = "C" + i;
var valToChk = sheet.getRange(cell) ;
if (sheet.getRange(cell)===targetSheet.getRange(cell) ){
setStrikeThru(targetSheet.getRange(cell));
}
}
}

我不知道我是否接近这一点。

基本上,我有一个主工作表“每周完成的作业”,我想将此工作表 C 列上的值与所有其他工作表上的 C 列进行比较,并在其他工作表上删除线(如果它存在于“每周完成的工作”中) ”

我已经成功编写了其他代码来复制行并根据值移动它们,但我无法在这个代码上获得正确的逻辑。 JavaScript 不是我的母语。感谢您的提前帮助。

最佳答案

您正在比较范围对象,这不起作用。您需要使用 range#getValues() 从范围中提取值并比较这些值。 。下面是一个可能对您有帮助的示例。

function compare() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var controlSheet = ss.getSheetByName("WEEKLY COMPLETED JOBS");
var column = 3;
var firstValueRow = 2;
var lastRow = controlSheet.getLastRow();
var controlValues = controlSheet.getRange(firstValueRow, column, lastRow).getValues();
var sheetsToCheck = ["Adia", "Alejandra", "Daniel", "David L"];
sheetsToCheck.forEach(function (sheetName) {
var sheetToCheck = ss.getSheetByName(sheetName);
if (!sheetToCheck) {
throw new Error("No sheet with name: " + sheetName);
}
var checkValues = sheetToCheck.getRange(firstValueRow, column, lastRow).getValues();
for (var i = 0; i < controlValues.length; i++) {
controlValue = controlValues[i][0];
if (controlValue) {
var checkValue = checkValues[i][0];
if (controlValue === checkValue) {
sheetToCheck.getRange(i + firstValueRow, column).setFontLine("line-through");
}
}
}
});
}

关于javascript - Google 表格将所有工作表上的列与同一列进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42428688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com