2015-04-03 17 views
1

我有一個這樣的搜索工具:如何更新同一行中沒有行返回在LASTROW谷歌應用程序腳本

https://sites.google.com/site/appsscriptexperiments/home/a-simple-search-tool-ui 

但把它放在面板上,添加一個編輯按鈕可以使txtboxes和更新按鈕保存更改。但是,我將如何更新我搜索過的同一行中的現有數據?可能嗎?是更新它,但它返回到最後一行。不在同一行。

function updatebutton(e){ 
    var ss = SpreadsheetApp.openById('exampleID').getActiveSheet(); 

    var sheet = SpreadsheetApp.getActiveSpreadsheet(); 

    var lastRow = ss.getLastRow(); 

    var row= ss.getDataRange().getRowIndex(); 

    var app = UiApp.getActiveApplication(); 

    var timestamp = e.timestamp = new Date() + 
    Session.getActiveUser().getUserLoginId(); 

    var txt0 = e.parameter.txt0; 

    var txt1 = e.parameter.txt1; 

    var txt2 = e.parameter.txt2; 

    var txt3 = e.parameter.txt3; 

    var data = ss.getRange(lastRow+1, 1, 1,4).setValues([[timestamp,txt1,txt2,txt3]]); 

    return app; 

} 

或者是否有可能確定我想從哪裏輸入數據?幫助不大。謝謝

+0

您發佈的代碼不顯示任何搜索功能。如果你有代碼發現問題,有辦法找出哪些行有信息被發現。但是你現在的代碼並不顯示任何可以找到任何信息的東西。 – 2015-04-03 16:08:40

回答

0

看來您正在使用搜索電子表格並在單元格中查找值的代碼。然後你想更新那些行數據。如果正在使用for循環,則for循環的計數可以與該行匹配。如果您正在獲取數據數組,然後查找數組中的值的索引,那麼索引號可以與行號匹配。

您可以獲取當前的活動行號。但是你需要在程序運行之前點擊你想更新的那一行。

var theActiveSheet = SpreadsheetApp.getActiveSheet().getName(); 
//Logger.log('theActiveSheet: ' + theActiveSheet); 

if (theActiveSheet === 'your sheet name') { 
    //Ask to Overwrite only if this is the correct sheet 
    var updateThisRow = Browser.msgBox('UPDATE CURRENT ROW?', 'Overwrite current rows data', Browser.Buttons.YES_NO); 
}; 

if (updateThisRow === 'yes') {  
    var currentRow = ss.getActiveCell().getRow(); 
    var data = ss.getRange(currentRow, 1, 1,4).setValues([[timestamp,txt1,txt2,txt3]]); 
}; 
+1

omg感謝您的回覆。我試過了,但沒有發生任何反應-_-看看我的應用程序和電子表格 – 2015-04-03 15:11:27

+0

我也看着這一個,但我不明白它的http://quabr.com/28397927/how-to-update -a-google-worksheet-with-javascript請看看謝謝 – 2015-04-03 15:40:17

+0

您需要使用調試工具。您可以在代碼中添加Logger.log('some text:'+ variableName)'語句,然後查看LOGS,查看代碼實際正在執行的內容,或者使用調試器遍歷代碼。 [故障排除](https://developers.google.com/apps-script/troubleshooting#using_the_debugger_and_breakpoints) – 2015-04-03 15:54:42

相關問題