尝试使用Google Script API读取电子表格中的单元格1,1 [英] Trying to read cell 1,1 in spreadsheet using Google Script API

查看:104
本文介绍了尝试使用Google Script API读取电子表格中的单元格1,1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一位经验丰富的程序员......我对OOP概念有了一个很好的理解,我一直在使用 PHP MySQL 最近。我开始涉足Google API脚本。我试图编写一个非常简单的程序来读取谷歌电子表格中的单元格1,1。该API不嵌入谷歌电子表格中,我需要它在SS之外运行。



以下是有问题的代码:

 函数email() {

//通过其ID

打开SS SS = SpreadsheetApp.openById(0AgJjDgtUl5KddE5rR01NSFcxYTRnUHBCQ0stTXNMenc);

//获取这个SS

的名字var name = ss.getName();

读取单元格1,1 *下面的行不起作用*

  var data = Range.getCell(0,0); 

我知道 getCell()是一个方法在Range类中。从我在资源中看到的情况来看,Range看起来是顶级/父级/超级类别。看看上面的粗体代码,我相信我已经创建了一个Range对象并试图从该对象中调用一个方法。我在这里做错了什么?



感谢您的期待!

解决方案

您必须首先获取Range对象。另外,getCell()不会返回单元格的值,而是返回单元格的Range对象。因此,使用
$ b

 函数email(){

// //打开SS by其ID

var ss = SpreadsheetApp.openById(0AgJjDgtUl5KddE5rR01NSFcxYTRnUHBCQ0stTXNMenc);

//获取这个SS

的名字var name = ss.getName(); //不需要

//读取单元格1,1 *下面的行不起作用*

// var data = Range.getCell(0,0);
var sheet = ss.getSheetByName('Sheet1'); //或者其他任何名字的图纸
var range = sheet.getRange(1,1);
var data = range.getValue();






$ p
Spreadsheet - > Sheet - >范围 - >单元格。

I'm a mildly experienced programmer ... I have an OK understanding of OOP concepts, I've been using PHP and MySQL lately. I've started to dabble with Google API Scripts. I'm trying to write a very simple program to read cell 1,1 in a google spreadsheet. The API is NOT embedded in the google spreadsheet, I need it to run outside of the SS.

Here is the code in question:

function email() {

// Opens SS by its ID

var ss = SpreadsheetApp.openById("0AgJjDgtUl5KddE5rR01NSFcxYTRnUHBCQ0stTXNMenc");

// Get the name of this SS

var name = ss.getName();

Read cell 1,1 * Line below doesn't work *

var data = Range.getCell(0, 0);

I understand that getCell() is a method within the Range class. From what I can see in the resources, it looks like Range is the top / parent / super class. Looking at the bold code above, I believe I have created a Range object and trying to call a method from that object. What am I doing wrong here??

Thanks for looking!

解决方案

You have to first obtain the Range object. Also, getCell() will not return the value of the cell but instead will return a Range object of the cell. So, use something on the lines of

function email() {

// Opens SS by its ID

var ss = SpreadsheetApp.openById("0AgJjDgtUl5KddE5rR01NSFcxYTRnUHBCQ0stTXNMenc");

// Get the name of this SS

var name = ss.getName();  // Not necessary 

// Read cell 1,1 * Line below does't work *

// var data = Range.getCell(0, 0);
var sheet = ss.getSheetByName('Sheet1'); // or whatever is the name of the sheet 
var range = sheet.getRange(1,1); 
var data = range.getValue();

}

The hierarchy is Spreadsheet --> Sheet --> Range --> Cell.

这篇关于尝试使用Google Script API读取电子表格中的单元格1,1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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