如何在Google表格中针对其他值检查一个值,然后查询具有匹配值的单元格的属性?

时间:2017-07-07 20:46:43

标签: google-apps-script google-sheets-api

我想检查JSON网址中的值与Google表格中定义范围内的值。

如果匹配,我想查询包含匹配值(其行,列等)的单元格的属性。

如何在Google Apps脚本中执行此操作?

2 个答案:

答案 0 :(得分:0)

您可以在Overview and SpreadsheetApp中找到有关Apps脚本中的电子表格操作的所有信息。你可以从那里开始。例如,查询行和列等属性的方法是getRowgetColumn

答案 1 :(得分:0)

没关系。我自己得到了答案。



var i = 0;

// Bringing in the data from the third-party into Google Sheets.
var groupJSON = UrlFetchApp.fetch('<ANY-JSON-URL>');
var groupObjectRaw = JSON.parse(groupJSON);
//  var groupObject = groupObjectRaw[0]; <--optional, for my use only

var membersGroupForm = groupObject.data['member'];
var projectsGroupForm = groupObject.data['project'];
var hoursGroupForm = groupObject.data['hours worked'];

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Details');

var membersRange = ss.getRange('Details!A:A');
var membersSheet = membersRange.getValues();

var projectsRange = ss.getRange('Details!1:1');
var projectsSheet = projectsRange.getValues();

function getRowNumber() {
  for (i; i < membersSheet.length; i++) {
    if (membersSheet[i][0] == membersGroupForm) {
      return i + 1;
    }
  }
}

var rowNumber = getRowNumber(i, membersSheet, membersGroupForm);
Logger.log(rowNumber);

function getColumnNumber() {
  for (var row in projectsSheet) {
    for (var col in projectsSheet[row]) {
      if (projectsSheet[row][col] == projectsGroupForm) {
        return parseInt(col) + 1;
      }
    }
  }
}

var columnNumber = getColumnNumber(projectsSheet, projectsGroupForm);
Logger.log(columnNumber);

var cell = ss.getRange(rowNumber, columnNumber);
cell.setValue(hoursGroupForm);
&#13;
&#13;
&#13;