从Google脚本中的单元格获取值 [英] Getting values from cells in google scripts
问题描述
我正在尝试为我的工作制作工作表。在Google脚本中,我创建了自定义菜单,以确保我的工作表能够正确发送电子邮件。但是现在我想从特定的单元格中获取价值,并检查它是否在下面,例如2,发送具有该值的电子邮件。现在,我有了:
I am trying to make working sheets for my work. In Google scripts, I've created "Custom Menu" for my sheet wich is sending email correctly. But now I want to get value from the specific cell and check if it is below, for example, 2, send an email with that value. For now, I have this:
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Custom Menu')
.addItem('First item', 'menuItem1')
.addSeparator()
.addToUi();
}
function menuItem1() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.alert('You clicked the first menu item!');
if( 'A1' > 3){
MailApp.sendEmail('luk...@gmail.pl', 'subject', 'message');
}
}
我不知道如何从中获取此值这个细胞。这个'If'只是我要执行的操作的一个示例,我知道它不起作用。在此先感谢您的任何帮助。
I don't know how to get this value from this cell. This 'If" is just an example of what I am trying to do, I know it is not working. Thank you in advance for any kind of help.
推荐答案
首先,您需要找到工作表:
First, You need to find the sheet:
var sheet = SpreadsheetApp.getActiveSheet();
然后,您需要指定一个单元格范围并获取值:
Then, you need to specify a cell range and get the value(s):
var value = sheet.getRange("A1").getValue();
您可以在此处浏览API以获得更多功能: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app
You can browse the API for more functions here: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app
这篇关于从Google脚本中的单元格获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!