解析谷歌表单中的一个表,然后将所有匹配的行数据存储在我可以从中提取信息的数组中(GAS/JavaScript)



如果我的代码很乱,很抱歉,我是编码新手。到目前为止,我一直能够使事情顺利进行。

我想解析我的数据库,从所有符合匹配条件的行中获取信息,并将这些信息存储在一个数组中,每组数据都在数组的新级别上。这样我就可以稍后在报告页面上打印这些信息。

问题:

当我调试此代码时;newArray";变量具有正确的数字"0";对象";,由于缺乏适当的编码语言,但每一个的内容都是";函数()";其中没有任何真实数据。因此,关于我如何在for循环中推送和/或获取数据的问题无法正常工作,我不太确定原因。

function kanbanView() {
var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
//  var activeSheet = activeSpreadsheet.getActiveSheet();
var activeSheet = activeSpreadsheet.getSheetByName("ACTIVE");
var activeRange = activeSpreadsheet.getActiveRange();
//  var activeCell = activeSpreadsheet.getActiveCell();
var activeCell = activeSheet.getRange(19, 10);
// ^^ remove later, mock cell for debugger.
var activeCellRow = activeCell.getRow();
var activeCellColumn = activeCell.getColumn();
var lastColumn = 17;
var firstColumn = 1;
var lastRow = activeSheet.getLastRow();
var activeCellValue = activeCell.getValue();
var findCriteria = activeCellValue;
var foundCriteria = 0;
var contentRange = activeSheet.getRange(1, 1, 5000, 17);
var contentRangeValues = contentRange.getValues();
var contentRangeFormats = contentRange.getFontColors();
var sourceColumn = 10;
//-------------------------------------------Parsing--------------------------------------------------
var foundValues = [];
var newArray = [];
var foundRow;
var iName;
var iStatus;
var iRating;
var iAction;
var iPosition;
var iLocation;
var iClient;
for (var i = 0; i < lastRow; i++) {
if (activeColumnRangeValues[i][0] == findCriteria) {
foundRow = i;
iName = activeSpreadsheet.getSheetByName("ACTIVE").getRange(foundRow, 7).getValue;
iStatus = activeSpreadsheet.getSheetByName("ACTIVE").getRange(foundRow, 5).getValue;
iRating = activeSpreadsheet.getSheetByName("ACTIVE").getRange(foundRow, 4).getValue;
iAction = activeSpreadsheet.getSheetByName("ACTIVE").getRange(foundRow, 6).getValue;
iPosition = activeSpreadsheet.getSheetByName("ACTIVE").getRange(foundRow, 8).getValue;
iLocation = activeSpreadsheet.getSheetByName("ACTIVE").getRange(foundRow, 9).getValue;
iClient = activeSpreadsheet.getSheetByName("ACTIVE").getRange(foundRow, 10).getValue;
newArray.push([iName, iStatus, iRating, iAction, iPosition, iLocation, iClient,
]);
foundValues.push(foundRow + 1);
}
}

我认为这符合您的要求:

function kanbanView() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("ACTIVE");
const vA = sh.getRange(1,1,sh.getLastRow(),17).getValues();
const findCriteria = sh.getRange(19, 10).getValue();
const newArray=[];
const foundValues=[];
vA.forEach((r,i)=>{
if(r[0]==findCriteria) {
newArray.push([r[6],r[4],r[3],r[5],r[7],r[8],r[9]]);
foundValues.push(i+1); 
}

});
console.log(JSON.stringify(newArray));
console.log(JSON.stringify(foundValues));
} 

这是我的数据:

COL10>td style="text align:left;">9>td style="text align=:left;">27<10><21>27<10>>>>26>>td style="ext-align:left;left;">4
COL1COL8COL9COL11COL17COL18COL19COL20
2025204
211102225
42375118
272689256121402921292
21211071517
192719291229119
2554266612
17618211311
173131138
20181611
28202828427
1221292218141527810914
157100610
2716281712
2111418270
21424212022
158125101160017
10021292212
1112615918
1927292825
111510156521191816
620251021
212275106
20242963
1776101426
1312271826250161614923
29281529121318262132503
22021405
2321213927
29280222312

相关内容

最新更新