Getting values from cells in google scripts

社会主义新天地 提交于 2020-06-26 12:06:14

问题


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');
  }
}

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.


回答1:


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();

You can browse the API for more functions here: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app



来源:https://stackoverflow.com/questions/44515670/getting-values-from-cells-in-google-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!