2

状況:

10 枚のシートと 15 人のユーザーがログインして変更しているスプレッドシートがあります。

スクリプト機能:

誰かが任意の列の行を変更すると、このスクリプトは lastcolumn を DateTime で更新し、その変更を行ったユーザーのコメントを挿入します。

問題:

(1) パフォーマンスの問題: このスクリプトは、ユーザーが列を変更したときに実行されます。これは、3 人以上のユーザーがスプレッドシートにログインして保存するのが遅い場合に発生する可能性があります。
(2) このスクリプトは、特定の列が変更された場合にのみ実行する必要があります。例: activeuser が列 A、B、C;D、E & I を変更した場合、スクリプトは最後の列 J を Date&Time で更新します。ただし、アクティブなユーザーが列 F、G、H を変更した場合、スクリプトは実行されません。

テストケース:

(1) このスクリプトは OnEdit を非常にうまく実行していますが、誰かが任意の列の任意の行を変更すると、lastcoulmn を更新しています。

特定の列が変更されたときにのみ実行されるように、このスクリプトを変更するのを手伝ってくれる人がいれば幸いです。

脚本:

    function onEdit(event)
    {
      var ss = SpreadsheetApp.getActiveSpreadsheet();

    //Script Last Update Timming

      var actSht = event.source.getActiveSheet();
      var actRng = event.source.getActiveRange();

      var index = actRng.getRowIndex();
      var dateCol = actSht.getLastColumn();
      var lastCell = actSht.getRange(index,dateCol);
      var date = Utilities.formatDate(new Date(), "GMT-3", "dd/MM/yyyy HH:mm");

      // Note: Insert the Date when someone update the row in the last coulmn
        lastCell.setValue(date);

      // Nota: Insert a comment in the lastCell with the user who modify that row
        lastCell.setComment(Session.getEffectiveUser());
    }
4

1 に答える 1

3

以下のコードを使用してアクティブな行とアクティブな列を確認し、識別された行、列に基づいて、さらに進むことができます。

var activeCell = sheet.getActiveCell();
var row = activeCell.getRow();
var column = activeCell.getColumn();

全体的なコードは次のようになります。

function onEdit(event){
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  //Script Last Update Timming

  var actSht = event.source.getActiveSheet();
  var actRng = event.source.getActiveRange();

  var activeCell = actSht.getActiveCell();
  var row = activeCell.getRow();
  var column = activeCell.getColumn();

  if(row < 2)   return; //If header row then return
  var colNums  = [1, 5, 6, 7]; //Coulmns, whose edit is considered
  if(colNums.indexOf(column) == -1) return; //If column other than considered then return


  var index = actRng.getRowIndex();
  var dateCol = actSht.getLastColumn();
  var lastCell = actSht.getRange(index,dateCol);
  var date = Utilities.formatDate(new Date(), "GMT-3", "dd/MM/yyyy HH:mm");

  // Note: Insert the Date when someone update the row in the last coulmn
  lastCell.setValue(date);

  // Nota: Insert a comment in the lastCell with the user who modify that row
  lastCell.setComment(Session.getEffectiveUser());
}
于 2013-06-10T03:34:27.040 に答える