2

我認爲這是專家。就在那兒,一步一步:Google Spreadsheet權限

  • 我創建了一個谷歌電子表格
  • 下面的腳本在其上運行:

/*Updated and maintain by internetgeeks.org*/ 
function onEdit(event) 
{ 
    var timezone = "GMT-3"; var timestamp_format = "dd-MM HH:mm"; // Timestamp Format. 

    if (updateColName = "Nº Cotação") { 
    var sheet = event.source.getSheetByName('Cotações'); //Name of the sheet where you want to run this script. 
    var updateColName = "Nº Cotação"; var timeStampColName = "Data proposta"; 
    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);} 

    if (updateColName = "Resposta ao Cliente") { 
    var sheet = event.source.getSheetByName('Cotações'); //Name of the sheet where you want to run this script. 
    var updateColName = "Resposta ao Cliente"; var timeStampColName = "Contatado"; 
    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);} 

    } 
} 
} 
  • 此電子表格與共享其他用戶,作爲編輯
  • 某些間隔限制某些e ditors

問題

  • 當所有者更新兩個描述列(見上面的代碼),腳本工作正常

  • 當共享編輯修改的東西,只是第二條件(如果)的腳本正在工作

有人可以幫助我嗎?

腳本有問題嗎?爲什麼它只能在電子表格所有者上正常工作?

+0

http://pt.stackoverflow.com/help/dont-ask可能是有趣的。 – pnuts

+0

看起來'updatedColName'是'undefined'。見http://stackoverflow.com/q/16089041/1595451 –

回答

0

而不是使用單一的 '='
使用雙 '==' 在你的代碼

更改聲明如下:

if (updateColName = "Nº Cotação") 

要:

if (updateColName == "Nº Cotação") 

,改變如下:

if (updateColName = "Resposta ao Cliente") 

要:

if (updateColName == "Resposta ao Cliente") 

UPDATE:
下面是完整的腳本代碼,應按照您的要求工作:

function onEdit(event) { 
    var actRng = event.source.getActiveRange(); 
    var actSheet = actRng.getSheet(); 
    if(actSheet.getName() == 'Cotações' && actRng.getRowIndex() > 1) { 
    var updateColName = actSheet.getRange(1,actRng.getColumn()).getValue(); 
    var headers = actSheet.getRange(1, 1, 1, actSheet.getLastColumn()).getValues(); 
    var date = Utilities.formatDate(new Date(),'GMT-3','dd-MM HH:mm'); 
    if(updateColName == 'Nº Cotação') { 
     var dateCol = headers[0].indexOf('Data proposta'); 
     actSheet.getRange(actRng.getRowIndex(),dateCol+1).setValue(date); 
    } 
    else if(updateColName == 'Resposta ao Cliente') { 
     var dateCol = headers[0].indexOf('Contatado'); 
     actSheet.getRange(actRng.getRowIndex(),dateCol+1).setValue(date); 
    } 
    } 
}; 
+0

嗨Kishan,謝謝,但是,這樣做後,代碼不再工作。 –

+0

嗨丹尼爾,我已經更新了我的答案,併發布了完整的代碼,應按照您的要求工作。 – Kishan

+0

好的,謝謝Kishan ...我用完整的代碼對它進行了測試,但問題依然存在! :( 只是第二如果(條件)正在爲另一個用戶工作...... –