如何解决“非法字符"问题?保存Google脚本时出现错误 [英] How to solve "illegal character" error when saving Google Script
问题描述
我正在尝试向Google Spreadsheet添加自定义函数.我看了看Google Spreadsheet自定义函数的教程,尽管它很显然,但我想我也遵循了它,但我遇到的问题似乎是如此基础,以至于我无法通过正确的查询来找到答案.
I am trying to add a custom function to a Google Spreadsheet. I looked at the tutorial for Google Spreadsheet custom function while it was clear insofar as it went, and i think I followed it, I am having problems that seem to be so basic I cant form the right query to find the answer.
我进入了有问题的Google Spreadsheet,打开了脚本管理器,选择NEW,Google Spreadsheet,它打开了一个窗口"Untitled Progject",其中包含"code.gs"文件,其中已有2个函数.我不知道为什么他们在那里,并假定我只是将我的内容附加到我做的末尾,如下所示:
I went into the Google Spreadsheet in question, opened up script manager, select NEW, Google Spreadsheet and it opens a window "Untitled Progject" with a "code.gs" file with 2 functions already in it. I dont know why they are there and presume that I just append mine to the end which I did as follows:
以"var WdName"开头的行是第38行,表示存在非法字符
The line beginning "var WdName" is line 38 where it says there is an illegal character
/**
* 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
};
任何帮助将不胜感激.我确实尝试在此论坛和其他地方进行搜索,尽管我怀疑那里有答案,但我找不到它.
Any help will be appreciated. I did try searching in this forum and elsewhere and while I suspect there is an answer there, I couldnt find it.
谢谢
推荐答案
实际上,引号对于Apps Script编辑器而言是无效字符,您只需更改即可解决其他双引号或单引号.
Indeed the quotes look a invalid character for Apps Script editor, you only need to change to solve the other double quote or single quote.
var wdName="NONE"; // change to -> var wdName="NONE";
以下行(39)中的引号有效:if (typeof inNum != "number")
The quotes in the following line (39) is valid: if (typeof inNum != "number")
它应该更改您看到的所有引号,代码中包含多个引号:
It should change all quotes that you see with this, there are several in the code:
...
wdName="Sunday"; // change to -> var wdName="Sunday";
...
wdName="Monday"; // change to -> var wdName="Monday";
...
这篇关于如何解决“非法字符"问题?保存Google脚本时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!