最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

SpreadsheetApp getLastRow() returns an exception when other users are viewing the google sheet - Stack Overflow

programmeradmin1浏览0评论

We have been running an app script to clear a shared google sheet for many years. All teachers are able to view this sheet as it is used for after school dismissal. The script has always been successful even if there are other teachers viewing the sheet. About a month ago, the script stopped working if any other user is viewing the sheet. The error return in the debug editor is "Exception: Service Spreadsheets failed while accessing document with id 18y1U3..."

function lastValue(column) {
  var lastRow = SpreadsheetApp.getActiveSheet().getMaxRows();
  var values = SpreadsheetApp.getActiveSheet().getRange(column + "1:" + column + lastRow).getValues();

  for (; values[lastRow - 1] == "" && lastRow > 0; lastRow--) {}
  return lastRow;
}


var spreadsheet = SpreadsheetApp.getActive();

const ss = SpreadsheetApp.getActiveSpreadsheet();

const ws = ss.getSheetByName("AddNamesHere");

const pickupws = ss.getSheetByName("PickupChanges");

//copy and paste pickup changes to perpetual list

spreadsheet.setActiveSheet(spreadsheet.getSheetByName('PickupChanges'), true);

pickupws.getRange(lastValue("F")+1,1).activate();

pickupws.getRange('H3:M15').copyTo(pickupws.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);

//uncheck boxes on column 13

spreadsheet.setActiveSheet(spreadsheet.getSheetByName('AddNamesHere'), true);

ws.getRange(2,13,ws.getLastRow() -1).setValue(false);

The error occurs when ws.getLastRow() is called.

I also tried to troubleshoot using this code:

/troubleshoot getlastrow

const sheet = ss.getSheets()[0];

// This logs the value in the very last cell of this sheet

const lastRow = sheet.getLastRow();

const lastColumn = sheet.getLastColumn();

const lastCell = sheet.getRange(lastRow, lastColumn);

Logger.log(lastCell.getValue());

The same error occurs when const lastRow = sheet.getLastRow() and const lastColumn = sheet.getLastColumn() is executed.

This error will only occur if another user is simply viewing the workbook. If no one is viewing it does not return an error. This script was working fine up until about a month ago.

"AddNamesHere" sheet sample markdown:

Multiple Rider List 1 Single Name List 1 Single Name List 2 Multiple Rider List 2 Multiple Rider List Single Name List Pick up change? Picked up by other: Date:
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE .
FALSE
FALSE
FALSE

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论