Редактирование интерактивной таблицы Google в Google Doc не работает - PullRequest
0 голосов
/ 03 июля 2018

У меня есть несколько проектов, и они уважают одну и ту же структуру, у них есть таблица из 8 строк и двух столбцов, и я до сих пор написал скрипт, который берет все документы и затем помещает их в таблицу с информацией в виде столбца. сценарий, связанный с контейнером, и я хочу, чтобы его использовали несколько пользователей. Я заблокирован на довольно длительное время, потому что я хочу сделать интерактивную, если я изменю в таблице, она изменится в Google Doc и наоборот. Я начинаю, я пытался с датой в столбце, если я изменю дату, а затем щелкните URL-адрес Документа Google, чтобы увидеть изменение, но оно не работает. Это мой код:

Изменить это мой новый измененный код:

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 Spreadsheed со скриптом внутри: https://docs.google.com/spreadsheets/d/1k_kj98U__0Bk44gh0qRFpaVx0ru3sN1pSPGiMQwimxo/edit?usp=sharing и моя папка с проектами Google Doc находится здесь: https://drive.google.com/drive/folders/1x1m7tqfoSY6yW5gvwoIoh9jRPuiqwADO?usp=sharing Любой Идея отличная :) Большое спасибо заранее enter image description hereenter image description here

1 Ответ

0 голосов
/ 04 июля 2018

Я пробовал другой код, который работает, только если я изменяю дату 4-го проекта в этом коде, я заменил только

data_sheet [activeRow] [column_date_project-1] с data_sheet [4] [column_date_project-1], поскольку activeRow не определен поэтому любая идея восстановить строку активной ячейки, когда я редактирую данные соответствующей ячейки, хороша.

/** 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 **/
      }
    }
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...