2

我正在尝试向 Google 电子表格添加自定义函数。我查看了 Google 电子表格自定义功能的教程,虽然它很清楚,但我想我遵循了它,我遇到的问题似乎很基本,我无法形成正确的查询来找到答案。

我进入有问题的谷歌电子表格,打开脚本管理器,选择新,谷歌电子表格,它会打开一个窗口“无标题项目”,其中包含一个“code.gs”文件,其中已经有 2 个函数。我不知道他们为什么在那里,并假设我只是将我的附加到我的末尾,如下所示:

以“var WdName”开头的行是第 38 行,它表示存在非法字符

 /**
 * Retrieves all the rows in the active spreadsheet that contain data and logs the
 * values for each row.
 * For more information on using the Spreadsheet API, see
 * https://developers.google.com/apps-script/service_spreadsheet
 */
function readRows() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var numRows = rows.getNumRows();
  var values = rows.getValues();

  for (var i = 0; i <= numRows - 1; i++) {
    var row = values[i];
    Logger.log(row);
  }
};

/**
 * Adds a custom menu to the active spreadsheet, containing a single menu item
 * for invoking the readRows() function specified above.
 * The onOpen() function, when defined, is automatically invoked whenever the
 * spreadsheet is opened.
 * For more information on using the Spreadsheet API, see
 * https://developers.google.com/apps-script/service_spreadsheet
 */
function onOpen() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{
    name : "Read Data",
    functionName : "readRows"
  }];
  sheet.addMenu("Script Center Menu", entries);
};

function DAYNAME(inNum) {
  // Function to convert from integers to Week Day names
  var wdName=“NONE”;     // this will hold the answer  
  if (typeof inNum != "number") {  // check to make sure input is a number
    throw "input must be a number";  // throw an exception with the error message
  }
    if (inNum == 1) {
    wdName=“Sunday”;
}
    if (inNum == 2) {
    wdName=“Monday”;
}
    if (inNum == 3) {
    wdName=“Tuesday”;
}
    if (inNum == 4) {
    wdName=“Wednesday”;
}
    if (inNum == 5) {
    wdName=“Thursday”;
}
    if (inNum == 6) {
    wdName=“Friday”;
}
    if (inNum == 7) {
    wdName=“Saturday”;
}

  return wdName;  // return the answer to the cell which has the formula
};

任何帮助将不胜感激。我确实尝试在这个论坛和其他地方搜索,虽然我怀疑那里有答案,但我找不到。

谢谢

4

1 回答 1

1

确实引号对于 Apps Script 编辑器看起来是一个无效字符,您只需要更改即可解决其他双引号或单引号。

var wdName=“NONE”; // change to -> var wdName="NONE";

以下行 (39) 中的引号是有效的:if (typeof inNum != "number")

它应该改变你看到的所有引号,代码中有几个:

...
wdName=“Sunday”; // change to -> var wdName="Sunday";
...
wdName=“Monday”; // change to -> var wdName="Monday";
...
于 2013-08-28T23:06:03.183 回答