如何使用应用脚本在GoogleSpreadSheet中的单元格中写入内容? [英] How to write in cells in GoogleSpreadSheet using app Script?

查看:92
本文介绍了如何使用应用脚本在GoogleSpreadSheet中的单元格中写入内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为这个愚蠢的问题感到抱歉.

and sorry for the stupid question.

我知道如何在VBA for Excel上编程,但是我很难在Google Spreadsheet中做最简单的事情,而我也找不到在线的好教程.

I know how to program on VBA for Excel, but I´m having a hard time doing the simplest stuff in Google Spreadsheet and I can´t find any good tutorials on-line.

我的问题是关于细胞的.在VBA中写一个单元格,我会这样做:

My question is regarding cells. In VBA to write in a cells I would do:

cells(1,1) = 2 //that would write the number 2 in the first row of the first column  

在VBA中,我还可以将单元格分配给变量,例如:

In VBA I can also assign a cell to a variable, like:

dim something as long
something = cells(1,1)

如何在Google SpreadSheet中应用相同的原则?

How can I apply the same principles in google SpreadSheet?

非常感谢!

我尝试了你们的建议.现在我有一个后续问题.

I´ve tried what you guys suggested. And now I have a follow up question.

我正在尝试在特定范围内修改单元格.我已经尝试过以下代码:

I`m trying to modify the cells in a specific range. I´ve tried this code:

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var board = sheet.getRange(2,2,9,9);
board[0][0].setValue(2);

但是显然我不能使用数组符号.我不确定.setValeu或.getRange是问题所在.但是有没有办法我可以使用数组符号来对一个单元进行赋值呢?

But apparently I can´t use array notation. I´m not sure if .setValeu or .getRange are the problem. But is there a way I can use array notation to chance a cell?

再次感谢!

推荐答案

尝试以下操作:

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = sheet.getRange(1,1);
cell.setValue(2);

这篇关于如何使用应用脚本在GoogleSpreadSheet中的单元格中写入内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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