google-apps-script - Google 表格脚本:对 https://script.google.com 的请求失败,返回代码 404
问题描述
只是想知道如果我开始收到以下错误是什么意思?它以前可以工作,但现在,每当我单击按钮时,我都会不断收到该错误。有人能帮我吗?谢谢!
例外:对https://script.google.com的请求失败,返回代码 404。截断的服务器响应:<meta name="viewport" c...(使用 muteHttpExceptions 选项检查完整响应)
这是我正在使用的脚本:
function doGet(e) {
this[e.parameter.run](e.parameter.sheetName || null);
return ContentService.createTextOutput();
}
function HideRows() {
const activeSheet = SpreadsheetApp.getActiveSheet();
const url = ScriptApp.getService().getUrl();
UrlFetchApp.fetch(url + "?run=script_HideRows&sheetName=" + activeSheet.getSheetName(), {headers: {authorization: "Bearer " + ScriptApp.getOAuthToken()}});
// DriveApp.getFiles() // This is used for automatically detecting the scope of "https://www.googleapis.com/auth/drive.readonly". This scope is used for the access token.
}
function showRows() {
const url = ScriptApp.getService().getUrl();
UrlFetchApp.fetch(url + "?run=script_showRows", {headers: {authorization: "Bearer " + ScriptApp.getOAuthToken()}});
}
var startRow = 11;
var colToCheck = 2;
// This script is the same with your "HideRows".
function script_HideRows() {
var sheetNames = ["AP_Q1", "AP_Q2", "AP_Q3", "AP_Q4", "SUMMARY OF QUARTERLY GRADES"]; // Please set the sheet names here. In this case, 4 sheets are used.
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.getSheets().forEach(sheet => {
var sheetName = sheet.getSheetName();
if (sheetNames.includes(sheetName)) {
if (sheetName == "SUMMARY OF QUARTERLY GRADES") { // When the sheet is "SUMMARY", the start row is changed.
startRow = 12;
}
var numRows = sheet.getLastRow();
var elements = sheet.getRange(startRow, colToCheck, numRows).getValues();
for (var i=0; i < elements.length; i++) {
if (shouldHideRow(sheet, i, elements[i][0])) {
sheet.hideRows(startRow + i);
}
}
// Hide the rest of the rows
var totalNumRows = sheet.getMaxRows();
if (totalNumRows > numRows)
sheet.hideRows(numRows+1, totalNumRows - numRows);
}
});
}
// This script is the same with your "showRows".
function script_showRows() {
// set up spreadsheet and sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// var ss = SpreadsheetApp.getActiveSpreadsheet(),
var sheets = ss.getSheets();
for(var i = 0, iLen = sheets.length; i < iLen; i++) {
// get sheet
var sh = sheets[i];
// unhide columns
var rCols = sh.getRange("1:1");
sh.unhideColumn(rCols);
// unhide rows
var rRows = sh.getRange("A:A");
sh.unhideRow(rRows);
}
};
function shouldHideRow(ss, rowIndex, rowValue) {
if (rowValue == "" || rowValue == '#REF!') return true; // <--- Added
if (rowValue != '') return false;
if (ss.getRange(startRow + rowIndex, colToCheck, 1, 1).isPartOfMerge()) return false;
if (ss.getRange(startRow + rowIndex + 1, colToCheck, 1, 1).isPartOfMerge()) return false;
return true;
}
解决方案
推荐阅读
- r - 使用 stringr 替换 NA 值
- sql - 具有 n 对 m 关系的 SQL 案例查询
- javascript - 查询不适用于 SQL 模板字符串 npm
- postgresql - 返回 SOQL 中表的所有数据类型
- node.js - 通过 Promise 调用 Rest API 直到结果成功
- javascript - 刷机与转场并存
- excel - 如何获取工作表代码名称以激活特定工作表?
- jquery - 将这些变量添加到数组或 JSON 以发送的最佳方式?
- python - 尝试使用 Flask 上传文件以在 AWS S3 上处理时不允许使用 405 方法
- amazon-web-services - Terraform AWS - 如何将默认路由更改为从 nat-gateway 到 ec2 的现有路由表?