简体   繁体   English

谷歌表脚本问题

[英]Google sheet Script issue

I'm trying to replicate a spreadsheet I saw online with modifications.我正在尝试复制我在网上看到的经过修改的电子表格。 The purpose of the spreadsheet is to document my Bull Put/Bear Call credit spreads.电子表格的目的是记录我的牛市看跌/熊市看涨信用利差。 The plan is to have a dashboard sheet where I can enter the info and by clicking the add position button, it will transfer the info into the data sheet where all logs will be held.计划是有一个仪表板表,我可以在其中输入信息,通过单击添加位置按钮,它将信息传输到数据表中,所有日志都将在其中保存。 I will also be able to close positions from the dashboard page, but I have not even begun that script as of yet.我还可以从仪表板页面平仓,但我什至还没有开始那个脚本。 The script I am putting together is.我正在整理的脚本是。

function AddPosition() {函数添加位置(){

var ss = SpreadsheetApp.getActiveSpreadsheet();
  var dashboard = ss.getSheetByName("Dashboard");
  var data = ss.getSheetByName("Data");
  var expiration = dashboard.getRange(7, 3).getValue();
  var sym = dashboard.getRange(7, 4).getValue();
  var contracts = dashboard.getRange(7, 5).getValue();
  var type = dashboard.getRange(7, 6).getValue();
  var shortleg = dashboard.getRange(7, 7).getValue();
  var longleg = dashboard.getRange(7, 8).getValue();
  var pop = dashboard.getRange(7, 9).getValue();
  var credit = dashboard.getRange(7, 10).getValue();

if (expiration=="" ||
    sym=="" || 
    contracts=="" || 
    type=="" || 
    shortleg=="" || 
    longleg=="" || 
    pop=="" || 
    credit=="" || {
      **var ui = SpreadsheetApp.getUi(); // Same variations.**
      var response = ui.alert('Missing data','Please fill in missing values and try again.', ui.ButtonSet.OK);
      return;
}

  data.insertRowAfter(data.getLastRow());
  var lastRow = data.getLastRow();
  var now = new Date();
   data.getRange(lastRow, 1).setValue(now);
   data.getRange(lastRow, 2).setValue(sym);
   data.getRange(lastRow, 3).setValue(type);
   data.getRange(lastRow, 4).setValue(expiration);
   data.getRange(lastRow, 6).setValue(longleg);
   data.getRange(lastRow, 7).setValue(shortleg);
   data.getRange(lastRow, 9).setValue(contracts);
   data.getRange(lastRow, 10).setValue(credit);
   data.getRange(lastRow, 13).setValue(pop);

   data.getRange(lastRow-1, 33).copyTo(data.getRange(lastRow, 33));
   data.getRange(lastRow-1, 34).copyTo(data.getRange(lastRow, 34));
   data.getRange(lastRow-1, 35).copyTo(data.getRange(lastRow, 35));
   data.getRange(lastRow-1, 36).copyTo(data.getRange(lastRow, 36));
   data.getRange(lastRow-1, 37).copyTo(data.getRange(lastRow, 37));

  dashboard.getRange(7,2,1,11 ).clearContent();

}

On line 23 "var ui = SpreadsheetApp.getUi(); // Same variations."第 23 行“var ui = SpreadsheetApp.getUi(); // 相同的变体。” I keep getting "SyntaxError:Unexpected identifier line:23 file: Code Gs".我不断收到“语法错误:意外的标识符行:23 文件:代码 Gs”。 I don't know what I'm doing wrong.我不知道我做错了什么。

Basically I'm trying say if data is missing, an alert will fire stating "'Missing data','Please fill in missing values and try again.'"基本上,我试图说如果数据丢失,则会发出警报,说明“'丢失数据','请填写缺失值并重试。'”

Can anyone help?任何人都可以帮忙吗?

I saw a few missing parenthesis within your if-else statement and also a few asterisks "*" on the declared var.我在您的if-else语句中看到了一些缺少的括号,并且在声明的 var 上还看到了一些星号“*”。 Fixed it up and it executed properly on my end.修复了它,它在我端正确执行。

Try this:尝试这个:

if (expiration=="" ||
sym=="" || contracts=="" || type=="" || shortleg=="" || longleg=="" || pop=="" || credit=="") {
var ui = SpreadsheetApp.getUi(); //Same variations.
var response = ui.alert('Missing data','Please fill in missing values and try again.', ui.ButtonSet.OK);
return;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM