保存Google Script时如何解决“非法字符”错误

时间:2013-08-28 21:34:40

标签: google-apps-script

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

我进入了有问题的Google电子表格,打开了脚本管理器,选择了新的Google电子表格,它打开了一个窗口“Untitled Progject”,其中包含“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
};

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

由于

1 个答案:

答案 0 :(得分:1)

对于Apps脚本编辑器,引号看起来是无效字符,您只需要更改以解决其他双引号或单引号。

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";
...