获取并设置单元格的值不起作用 [英] get and set Value of a Cell do not work

查看:90
本文介绍了获取并设置单元格的值不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在电子表格中从单元格获取值时遇到问题。我在文档中找到了getCell() - 方法,但它不起作用。它总是得到范围而不是价值。 (这是一个整数btw。)
而我没有找到一个setCell() - 方法! oO值在单元格B:1
Thx for any help !! 1:)

I have trouble with getting a Value from a Cell in my Spreadsheet. I found the getCell()-method in the documentation but it does not work. It always just gets "Range" instead of the Value. (it is a integer btw.) And I don't find a setCell()-method ! o.O The Value is in the cell B:1 Thx for any help!!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 );
}


推荐答案

getCell对象..您需要添加.getValue()方法以获取该范围内单元格的值。

getCell() returns a Range object.. you need to add the .getValue() method to get the value of the cell in the range.

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

这篇关于获取并设置单元格的值不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆