2017-06-08 23 views
0

私は仕事のためにスプレッドシートで作業しています.2つのスクリプトを使用する必要がありますが、私は "スクリプトエディタ"私はこれらの2つのスクリプトをマージする方法を知らないので、セルが編集されたときにそれらのスクリプトが同時に機能します。ご助力ありがとうございます! 2つのスクリプトは次のとおりです。2つのスクリプトを1つのgoogleシートに結合する

****まず1 ****

/** 
* Automatically sorts the 1st column (not the header row) Ascending. 
*/ 
function onEdit(event){ 
    var sheet = event.source.getActiveSheet(); 
    var editedCell = sheet.getActiveCell(); 

    var columnToSortBy = 4; 
    var tableRange = "A2:T99"; // What to sort. 

    if(editedCell.getColumn() == columnToSortBy){ 
    var range = sheet.getRange(tableRange); 
    range.sort({ column : columnToSortBy, ascending: false }); 
    } 
} 

****第二1:*****

function onEdit(event) 
{ 
    var timezone = "UTC-5"; 
    var timestamp_format = "mm-dd-yyyy'Time:' hh:mm:ss"; 
    var updateColName = "Parent Sign-Out"; 
    var timeStampColName = "Timestampt"; 
    var sheet = event.source.getSheetByName('Sheet1, Sheet2'); //Name of the sheet where you want to run this script. 


    var actRng = event.source.getActiveRange(); 
    var editColumn = actRng.getColumn(); 
    var index = actRng.getRowIndex(); 
    var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues(); 
    var dateCol = headers[0].indexOf(timeStampColName); 
    var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1; 
    if (dateCol > -1 && index > 1 && editColumn == updateCol) { // only timestamp if 'Last Updated' header exists, but not in the header row itself! 
    var cell = sheet.getRange(index, dateCol + 1); 
    var date = Utilities.formatDate(new Date(), timezone, timestamp_format); 
    cell.setValue(date); 
    } 
} 

} 

答えて

0

あなたが尋ねたとして、あなたがそれらを組み合わせることができ:

/** 
 
* Automatically sorts the 1st column (not the header row) Ascending. 
 
*/ 
 
function onEdit(event){ 
 
    var sheet = event.source.getActiveSheet(); 
 
    var editedCell = sheet.getActiveCell(); 
 

 
    var columnToSortBy = 4; 
 
    var tableRange = "A2:T99"; // What to sort. 
 

 
    if(editedCell.getColumn() == columnToSortBy){ 
 
    var range = sheet.getRange(tableRange); 
 
    range.sort({ column : columnToSortBy, ascending: false }); 
 
    } 
 
    // 2nd script 
 
    var timezone = "UTC-5"; 
 
    var timestamp_format = "mm-dd-yyyy'Time:' hh:mm:ss"; 
 
    var updateColName = "Parent Sign-Out"; 
 
    var timeStampColName = "Timestampt"; 
 
    var sheet = event.source.getSheetByName('Sheet1, Sheet2'); //Name of the sheet where you want to run this script. 
 

 

 
    var actRng = event.source.getActiveRange(); 
 
    var editColumn = actRng.getColumn(); 
 
    var index = actRng.getRowIndex(); 
 
    var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues(); 
 
    var dateCol = headers[0].indexOf(timeStampColName); 
 
    var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1; 
 
    if (dateCol > -1 && index > 1 && editColumn == updateCol) { // only timestamp if 'Last Updated' header exists, but not in the header row itself! 
 
    var cell = sheet.getRange(index, dateCol + 1); 
 
    var date = Utilities.formatDate(new Date(), timezone, timestamp_format); 
 
    cell.setValue(date); 
 
    } 
 
} 
 
    
 
}

それとものonEdit関数から第二の関数を呼び出すことができます。

/** 
 
* Automatically sorts the 1st column (not the header row) Ascending. 
 
*/ 
 
function onEdit(event){ 
 
    var sheet = event.source.getActiveSheet(); 
 
    var editedCell = sheet.getActiveCell(); 
 

 
    var columnToSortBy = 4; 
 
    var tableRange = "A2:T99"; // What to sort. 
 

 
    if(editedCell.getColumn() == columnToSortBy){ 
 
    var range = sheet.getRange(tableRange); 
 
    range.sort({ column : columnToSortBy, ascending: false }); 
 
    } 
 
    onEdit2(); 
 
} 
 

 

 
function onEdit2(event){ 
 
    var timezone = "UTC-5"; 
 
    var timestamp_format = "mm-dd-yyyy'Time:' hh:mm:ss"; 
 
    var updateColName = "Parent Sign-Out"; 
 
    var timeStampColName = "Timestampt"; 
 
    var sheet = event.source.getSheetByName('Sheet1, Sheet2'); //Name of the sheet where you want to run this script. 
 

 

 
    var actRng = event.source.getActiveRange(); 
 
    var editColumn = actRng.getColumn(); 
 
    var index = actRng.getRowIndex(); 
 
    var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues(); 
 
    var dateCol = headers[0].indexOf(timeStampColName); 
 
    var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1; 
 
    if (dateCol > -1 && index > 1 && editColumn == updateCol) { // only timestamp if 'Last Updated' header exists, but not in the header row itself! 
 
    var cell = sheet.getRange(index, dateCol + 1); 
 
    var date = Utilities.formatDate(new Date(), timezone, timestamp_format); 
 
    cell.setValue(date); 
 
    } 
 
} 
 

関連する問題