Google apps script 如何解决;“非法字符”;保存Google脚本时出错

Google apps script 如何解决;“非法字符”;保存Google脚本时出错,google-apps-script,Google Apps Script,我试图添加一个自定义功能到谷歌电子表格。我看了谷歌电子表格自定义功能的教程,虽然它是明确的,但我认为我遵循了它,我有一些问题,似乎是如此基本,我无法形成正确的查询来找到答案 我进入有问题的谷歌电子表格,打开脚本管理器,选择新建,谷歌电子表格,它打开了一个窗口“Untitled Progject”,其中有一个“code.gs”文件,其中已经有两个函数。我不知道他们为什么会在那里,并假设我只是将我的附加到结尾,我做了如下操作: 以“var WdName”开头的行是第38行,其中表示存在非法字符 /

我试图添加一个自定义功能到谷歌电子表格。我看了谷歌电子表格自定义功能的教程,虽然它是明确的,但我认为我遵循了它,我有一些问题,似乎是如此基本,我无法形成正确的查询来找到答案

我进入有问题的谷歌电子表格,打开脚本管理器,选择新建,谷歌电子表格,它打开了一个窗口“Untitled Progject”,其中有一个“code.gs”文件,其中已经有两个函数。我不知道他们为什么会在那里,并假设我只是将我的附加到结尾,我做了如下操作:

以“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
};
/**
*检索活动电子表格中包含数据和日志的所有行
*每行的值。
*有关使用电子表格API的更多信息,请参见
* https://developers.google.com/apps-script/service_spreadsheet
*/
函数readRows(){
var sheet=SpreadsheetApp.getActiveSheet();
var rows=sheet.getDataRange();
var numRows=rows.getNumRows();
var values=rows.getValues();

对于(var i=0;i实际上,引号对于应用程序脚本编辑器来说是无效字符,您只需更改以解决另一个双引号或单引号

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

当您选择“脚本类型”时,编辑器会通过提供一些示例代码来帮助您—在本例中,是操作电子表格的简单函数。您始终可以选择“空白脚本”-这不是很空白,因为它有一个空函数,但足够接近。这完全解决了问题。谢谢!!我可能应该使用某种面向编程的文本编辑器,而不是LibreOffice并保存为.txt。我不知道它会保存一种以上的双引号。