交互式 Google 电子表格到 Google 文档编辑不起作用

Interactive Google Spreadsheet to Google Doc edit not working

我有几个项目,它们遵循相同的结构,它们有一个 table 8 行和两列,到目前为止我写了一个脚本来获取所有文档,然后将它们放在 table 信息为 column.It 是一个容器绑定脚本,我想被几个人使用 users.I 被阻止了很长时间,因为如果我在 [=37] 中修改我想进行交互=] 它将在 Google 文档中修改,副 verso.I 开始 我尝试使用日期列,如果我修改日期然后单击 Google 的 url医生看到了变化,但它没有 work.This 是我的代码:

编辑 这是我新修改的代码:

function modify_Date_Google_Spreadsheet_to_Google_Doc_Project(e) {
  
  find_columns_in_projet();
  Logger.log(">> The column URL >> " + COLUMN_URL );
  Logger.log("The column date where we will modify it " +  column_date_project);
  
  var tss = SpreadsheetApp.openById(SPREADSHEET_ID);
  var sheet = tss.getSheets()[0];
  var numRows = sheet.getLastRow();
  var lastColumn = sheet.getLastColumn();
  
  //from the second line car the first line we have the headers
  var data = sheet.getRange(1,1,numRows,lastColumn).getDisplayValues();
  
  if ( ( e.range.getColumnIndex() == column_date_project )  )
  {
    var activeRow = SpreadsheetApp.getActiveRange().getRowIndex();
    var URL = e.range.offset(0,1,1,1).getValue();
    Logger.log('The URL is : ' + URL );
    var body = DocumentApp.openByUrl(URL).getBody();
    Logger.log('The body is ' + body );
    if(body)
    {
      var ok = 0;                                    //for the moment we don't have the table to modify the values we've put in the spreadsheet 
      var numChildren=body.getNumChildren();
      var compteur=0;
      //while we don't find the table we will search
      while(ok ==0 && compteur<numChildren)
      {
        var child=body.getChild(compteur);
        /** =========We are concerned by the first table with at least 8 rows ===**/
        Logger.log('the type in the loop  ' + child.getType());
        
        //here is our table  **/
        if(child.getType()==DocumentApp.ElementType.TABLE && child.asTable().getNumRows() >= 8)
        {
          //so the variable gets 1 >>  ok = 1
          ok=1;   
          
          /**  The number of rows in the Google Doc table **/
          var numrows = child.asTable().getNumRows();
          Logger.log('The number of rows is   ' + numrows);
          //Logger.log('The new date is ' + data[activeRow][colonne_date_de_projet-1]);
          /** we will loop in the table **/ 
          
          var k = 1;     //we know the information is at right so we don't loop we will replace the value 
          /**  is not working   **********************************************/
          //child.asTable().getCell(7, k).editAsText().setText( data[activeRow][column_date_project-1] )  ;
         
          
          /**** is working   ***/
          child.asTable().getCell(7, k).editAsText().setText( 10 )  ;
        }
        compteur++;       /** until we find our table **/
      }
    }
  }
}

这是一个编辑触发器,因为我在项目中还有另一个触发器这是 Google 电子表格,里面有脚本:https://docs.google.com/spreadsheets/d/1k_kj98U__0Bk44gh0qRFpaVx0ru3sN1pSPGiMQwimxo/edit?usp=sharing and my folder with the Google Doc projects is here : https://drive.google.com/drive/folders/1x1m7tqfoSY6yW5gvwoIoh9jRPuiqwADO?usp=sharing Any idea is great :) thank you very much in advance

我尝试了另一个代码,只有当我修改这段代码中第 4 个项目的日期时才有效我只替换了

data_sheet[activeRow ][column_date_project-1] with data_sheet[4][column_date_project-1] because activeRow is undefined so any idea to recover the row of the active cell when I edit the data corresponding cell is great.

/** working with 4 as the 4 row's date modifies****/
function works(e) {
  
  find_columns_in_projet();
  Logger.log(">> The column URL >> " + COLUMN_URL );
  Logger.log("The column date where we will modify it " +  column_date_project);
  
  var tss_bis = SpreadsheetApp.openById(SPREADSHEET_ID);
  var sheet_bis = tss_bis.getSheets()[0];
  var numRows_bis = sheet_bis.getLastRow();
  var lastColumn_bis = sheet_bis.getLastColumn();
  
  //from the second line car the first line we have the headers
  var data_sheet = sheet_bis.getRange(1,1,numRows_bis,lastColumn_bis).getDisplayValues();
  
  if ( ( e.range.getColumnIndex() == column_date_project )  )
  {
    var activeRow = SpreadsheetApp.getActiveRange().getRowIndex();
    
    Logger.log('The active row  is : ' + activeRow );
    var URL = e.range.offset(0,1,1,1).getValue();
    Logger.log('The URL is : ' + URL );
    var body = DocumentApp.openByUrl(URL).getBody();
    Logger.log('The body is ' + body );
    if(body)
    {
      var ok = 0;                                    //for the moment we don't have the table to modify the values we've put in the spreadsheet 
      var numChildren=body.getNumChildren();
      var compteur=0;
      //while we don't find the table we will search
      while(ok ==0 && compteur<numChildren)
      {
        var child=body.getChild(compteur);
        /** =========We are concerned by the first table with at least 8 rows ===**/
        Logger.log('the type in the loop  ' + child.getType());
        
        //here is our table  **/
        if(child.getType()==DocumentApp.ElementType.TABLE && child.asTable().getNumRows() >= 8)
        {
          //so the variable gets 1 >>  ok = 1
          ok=1;   
          
          /**  The number of rows in the Google Doc table **/
          var numrows = child.asTable().getNumRows();
          Logger.log('The number of rows is   ' + numrows);
          Logger.log('The new date is ' + data_sheet[4][column_date_project-1]);
         
          /** we will loop in the table **/ 
          
          var k = 1;     //we know the information is at right so we don't loop we will replace the value 
          /**  is working   **********************************************/
          child.asTable().getCell(7, k).editAsText().setText( data_sheet[4][column_date_project-1] )  ;
        }
        compteur++;       /** until we find our table **/
      }
    }
  }
}