3

スプレッドシートのセルから値を取得するのに問題があります。ドキュメントで getCell() メソッドを見つけましたが、機能しません。値の代わりに常に「範囲」を取得します。(これは整数です。)そして、setCell()メソッドが見つかりません!oO 値はセル 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 );
}
4

2 に答える 2

5

RangeオブジェクトgetRange()getCell()返します。データを取得するには、呼び出しまたは範囲を取得する必要があります。この場合、最初は単一のセルのみを参照しているため、必要はありませんgetValue()getValues()getRange("B1")getCell(1,1)

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

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

設定についても同様です。1 つのセル内の 1 つの値は次のようになります。

Range.setValue( number | string )

または、行と列がたくさんある場合は、最初に適切なサイズの範囲を選択してから使用しますsetValues([][])

于 2013-10-22T14:57:48.863 に答える