这是设置
我们根据项目分数与所有员工进行比赛。每个项目有两类员工(每个类别4名员工)和两个分数(每个员工类别一个)。
我需要抓住员工的所有分数并将其输出到电子表格中。 The following spreadsheet has misc. columns removed
表格说明
标有“示例数据”的表格是我们将从中提取数据的来源
标题为“示例输出”的工作表是我想在另一个名为“竞赛结果”的电子表格中生成的,其中包含来自工作表的工作表名称(它们以日期范围命名)。
我发现这个Removing Duplicates Article似乎至少处理了这些信息并以我认为可以做到的方式进行比较,但由于缺乏经验而未能使其发挥作用。
直到有人评论,才知道Transpose是什么:) 以下是另一篇文章中的解决方案,介绍如何使用Google Apps脚本和使用电子表格选项。 How to split and transpose results over 2 columns
这是我用来使其工作的实际代码(这有点可怕,但我尝试过)建议如何改进这个?:
function createScoreSheet() {
// Get Source spreadsheet
var source = SpreadsheetApp.getActive();
var sourceSheet = source.getActiveSheet();
var SourceActivate = sourceSheet.activate();
// Set Sheet Name
var sheetName = sourceSheet.getSheetName();
// Set Values to transpose and combine
var sourceEditor = sourceSheet.getRange("C1:C51");
var sourceWeb = sourceSheet.getRange("D1:D51");
var editorScores = sourceSheet.getRange("L1:L51");
var webScores = sourceSheet.getRange("K1:K51");
// Used to create a new spreadsheet
var sheetNameNew = sheetName + " Scores";
var createSheet = SpreadsheetApp.getActive().insertSheet(sheetNameNew,0);
var targetSheet = source.getSheetByName(sheetNameNew);
var totalScore = 1;
// s is the the counter we use to stick values into the rows
var s = 3;
// n is the the counter we use to stick values into the columns
var n = 1;
// loops through twice, once for the editor values, once for the webmaster
for (var j = 1; j<3; j++) {
if (j == 1) {
// grab values for the editors and copy to new sheet
sourceEditor.copyTo(targetSheet.getRange("A1"));
editorScores.copyTo(targetSheet.getRange("B1"));
// delete the header row then sort the column ASC by default
targetSheet.deleteRow(n);
targetSheet.sort(1);
// Find the last value to see how many scores we have
var lastRow = targetSheet.getLastRow();
}
if (j == 2) {
// grab values for the webmasters and copy to new sheet
sourceWeb.copyTo(targetSheet.getRange(n,1));
webScores.copyTo(targetSheet.getRange(n,2));
// delete the header row then sort the column ASC by default
targetSheet.deleteRow(n);
lastRow = targetSheet.getLastRow();
targetSheet.getRange(n,1,lastRow,2).sort(1);
lastRow = targetSheet.getLastRow();
}
// this loop will check to see if the value of the cell is equal to the next on the list and move the score
for (var i = 1; i<lastRow+1; i++) {
// Grab the name of the current row and the next
var firstName = targetSheet.getRange(n,1).getValue();
var nextName = targetSheet.getRange(n+1,1).getValue();
// Grab the scores
var oldScore = targetSheet.getRange(n+1,2);
var newScore = targetSheet.getRange(n,s);
// Loop to check to see if the firstname is blank and break to find the next value
if (firstName === "") {
break;
}
// checks to see if name is equal to the next then shifts then copies the score and adjust the horizontal position
if (firstName == nextName) {
totalScore = oldScore + newScore;
oldScore.copyTo(newScore);
s = s+1;
targetSheet.deleteRow(n+1);
}
// resets horizontal position for the score and increases the row
else {
s=3;
n=n+1;
}
}
// kills remaining rows
targetSheet.deleteRows(n,37);
}
}
答案 0 :(得分:0)
我会这样做:
如果您想自动生成名称,请将其写入输出表A1:
= unique('示例数据'!B2:B) - 此函数只生成A2-A5单元格的编辑器名称。
现在将此内容写入B2单元格:
=转置(过滤器('示例数据'!E:E,'示例数据'!B:B = A2)) - 此函数根据行开头的给定名称过滤编辑器点(在此案例A2)。然后以水平形式转换结果。要获得其他行的结果,只需填充此公式即可。
我想你可以找到其余的。 :)
希望它有所帮助。