2013-10-22 35 views
3

我無法從我的電子表格中的單元格獲取值。我在文檔中找到了getCell() - 方法,但它不起作用。它總是得到「範圍」而不是價值。 (這是一個整數btw。) 而我沒有找到一個setCell() - 方法! o.O值是小區B:1個 THX對於任何幫助!1 :)獲取並設置單元格的值不起作用

var API_KEY   = "***", 
    PROFILE_ID  = "****"; 
    GET_PLUS_ONES_URI = "https://www.googleapis.com/plus/v1/people/"+PROFILE_ID+"?fields=plusOneCount&key="+API_KEY; 
var currentPlusOnes = 0, 
    lastPlusOnes = 0, 
    ss    = SpreadsheetApp.getActive(); 

function execute() { 
    getCurrentPlusOnes(); 
    getLastPlusOnes(); 
    if (currentPlusOnes !== getLastPlusOnes) { 
    setCurrentValue(); 
    } 
} 

function getCurrentPlusOnes() { 
    currentPlusOnes = JSON.parse(UrlFetchApp.fetch(GET_PLUS_ONES_URI)).plusOneCount; 
} 

function getLastPlusOnes() { 
    lastPlusOnes = ss.getRange("B1").getCell(1, 1); // --> Allways just "Range" instead of the value 
} 

function setCurrentValue() { 
    ss.getDataRange().setValue(currentPlusOnes); 
} 
+3

lastPlusOnes = ss.getRange( 「B1」)的getValue(); – ScampMichael

回答

2

兩個getRange()getCell()返回範圍對象。您需要撥打電話getValue()getValues()以獲取數據。在這種情況下,你的第一個getRange("B1")只引用一個單元格,你不需要getCell(1,1)

lastPlusOnes = ss.getRange("B1").getValue(); 

https://developers.google.com/apps-script/reference/spreadsheet/range#getValue()

設置同樣適用。在單個小區中的單個值將是:

Range.setValue(number | string) 

,或者如果你有AA一堆的行和列,然後第一選擇適當的尺寸範圍,然後使用setValues([][])

相關問題