Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 我需要你帮我拿这个“;至于;循环和;如果;工作说明_Google Apps Script_Google Sheets_Google Sheets Macros - Fatal编程技术网

Google apps script 我需要你帮我拿这个“;至于;循环和;如果;工作说明

Google apps script 我需要你帮我拿这个“;至于;循环和;如果;工作说明,google-apps-script,google-sheets,google-sheets-macros,Google Apps Script,Google Sheets,Google Sheets Macros,整个脚本依赖于For循环和If语句的两种组合。两者基本相同。但出于某种原因,我可以让第一部分工作,但不能让第二部分工作 我已将我的脚本包括在下面的注释中。多谢各位 /** @OnlyCurrentDoc */ function onEdit(e) { //This part ensures the main script only runs if the cell F6 in the sheet "Daily Data" is edited. if ( e.source.getS

整个脚本依赖于For循环和If语句的两种组合。两者基本相同。但出于某种原因,我可以让第一部分工作,但不能让第二部分工作

我已将我的脚本包括在下面的注释中。多谢各位

/** @OnlyCurrentDoc */

function onEdit(e) {

//This part ensures the main script only runs if the cell F6 in the sheet "Daily Data" is edited.
  if (
    e.source.getSheetName() == "Daily Data" &&
    e.range.columnStart == 6 &&
    e.range.columnEnd == 6 &&
    e.range.rowStart >= 6 &&
    e.range.rowEnd <= 6 
  ) {

    //Secction 1: This section finds the lowest # from a list of numbers by finding the lowest empty cell in coloumn D using an If statement:
      var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
      var daily_data = spreadsheet.getSheetByName("Daily Data");
      var entirelistoftimes = daily_data.getRange(3, 4, 62).getValues();  
          for(var i=0; i<entirelistoftimes.length ; i++){  //This For loop will run through the entire D column in sheet "Daily Data".
            if (entirelistoftimes[i] == ""){        //This If statement will look for the first empty cell.
              //Copies the Total Number:
              var TotalNo = daily_data.getRange(i+2, 2).getValues();   //Gets the # from the cell next to the last filled cell in column D.
                spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Daily Data'), true);
              spreadsheet.getRange('F8').setValues(TotalNo);  //Displays the # in a cell F8 in sheet "Daily Data".
            //Stop once the first blank cell has been found:
            break;
          }
        }

    //THIS IS THE SECTION I CANNOT GET TO WORK:
    //Section 2: This section uses the # we got from the above section to find a time from a the corresponding row of sheet "Long Term Data":
      var LTD_data = spreadsheet.getSheetByName("Long Term Data");
      var LTD_data_entirelistoftimes = LTD_data.getRange(6, 2, 65).getValues();  
          for(var j=0; j<LTD_data_entirelistoftimes.length ; j++){  //This For loop will run through the Long Term Data sheet, through the list of numbers column.
            if (LTD_data_entirelistoftimes[j] == TotalNo){        //This if statement will look through column B from row 6 for the # we got from section 1 above.
              //Copies the time from column D in Lon:
              var YesterdayTime = LTD_data.getRange(j, 4).getValues();    //Gets the time from column D in row j in the "Long Term Data" Sheet.
                spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Daily Data'), true);
                spreadsheet.getRange('F9').setValues(YesterdayTime);  //Displays the time from the time underneath the # in sheet "Daily Data".
            //Stop once the above has been completed:
            break;
          }
        }
      }
}
;
/**@仅限当前文档*/
功能OneEdit(e){
//此部分确保仅在编辑工作表“每日数据”中的单元格F6时运行主脚本。
如果(
e、 source.getSheetName()=“每日数据”&&
e、 range.columnStart==6&&
e、 range.columnEnd==6&&
e、 range.rowStart>=6&&

e、 range.rowEnd如果脚本被修改,那么下面的修改如何

修改点:
  • 在脚本中,
    if(LTD_data_entirelistoftimes[j]==TotalNo){
    LTD_data_entirelistoftimes[j]
    TotalNo
    分别是一维数组和二维数组。因为
    getValues()
    返回二维数组。我认为问题的原因是直接比较这些值
修改脚本: 请按如下方式修改您的脚本

模式1: 当比较运算符使用
==
时,您可以进行如下修改

发件人: 致: 或

模式2: 当比较运算符使用
==
时,可以进行如下修改

发件人: 致: 注:
  • if(entirelistoftimes[i]==”){
    ,使用
    ==
    作为比较运算符。因此if语句可以工作
参考资料:

如果此修改未能解决您的问题,我深表歉意。届时,您能否提供一份电子表格样本?通过此,我希望对其进行修改。

完美!谢谢:)@Nagaram92感谢您的回复。我很高兴您的问题得到解决。
if (LTD_data_entirelistoftimes[j] == TotalNo){
if (LTD_data_entirelistoftimes[j] == TotalNo[0][0]){
if (LTD_data_entirelistoftimes[j][0] == TotalNo[0][0]){
if (LTD_data_entirelistoftimes[j] == TotalNo){
if (LTD_data_entirelistoftimes[j][0] === TotalNo[0][0]){