После трех дней экспериментов и поиска я все еще не могу заставить работать функцию .getValue - PullRequest
0 голосов
/ 28 февраля 2019

Извините за длинную тему, но этот сайт не принял бы более сжатое утверждение.

У меня есть Google Sheet, в котором нет ничего, кроме моего имени в ячейке A1.

Затем я зашел в Tools / Script Editor, и у меня есть скрипт «Code.gs», который говорит:

function onEdit(e) {
  Logger.log("We're in the function.");

  var ss = Spreadsheet.App.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var valueOfCell = sheet.getRange(1,1).getDisplayValue();
  Logger.log("Value of Cell is '" + valueOfCell + "'.");
}

Когда я редактирую свой очень простой лист и проверяю журнал (View / Logs), яполучить:

[19-02-28 08:58:10:182 CST] We're in the function.

Вот и все.Я попробовал каждую перестановку, о которой я могу подумать или найти за три дня веб-поиска, и я просто не могу заставить работать .getValue () (или .getDisplayValue ()).

Что я делаюне так?

Спасибо!

/ Кент

Ответы [ 2 ]

0 голосов
/ 01 марта 2019

Через четыре дня, я думаю, я наконец-то понял это.Для других, столь же плотных, как я, я оставляю эту документацию здесь:

Электронная таблица - это «рабочая книга», коллекция из Лист вкладок Лист это лист отдельной вкладки в электронной таблице"рабочей тетради".

Выглядит как достаточно простая информация, но я нигде не смог найти эту документацию.

SpreadsheetApp - это класс, «родитель» всех таблиц.Хотя, вероятно, технически неточно, для целей моего размышления я считаю, что SpreadsheetApp - это приложение «Листы» в Документах Google, а не «Документы» или «Слайды».

Итак,

var ThisApp = SpreadsheetApp;
// Sets the variable "ThisApp" to "SpreadsheetApp", which I guess is the name/identification of the spreadsheet app.

var TheActiveWorkBook = SpreadsheetApp.getActive();
// Sets "TheActiveWorkBook" to the identifier for the current collection of sheets (collection of tabs within a spreadsheet).

var TheActiveWorkBook = SpreadsheetApp.getActiveSpreadsheet();
// Identical to above; just a different name for it.

var ActiveWorkBookName = SpreadsheetApp.getActive().getName();
// Sets the variable to the *name* of the workbook/spreadsheet (like, "Fred's Spreadsheet").

var ActiveSheetInWB = SpreadsheetApp.getActiveSpreadsheet();getActiveSheet();
// Sets the variable to the identifier of the active tab in the spreadsheet.

var ActiveSheetInWB = SpreadsheetApp.getActive();getActiveSheet();
// Identical to above.

var ActiveSheetInWB = SpreadsheetApp.getActiveSheet();
// Identical to above. The active sheet is the active sheet, regardless of whether we know the active spreadsheet, so the extra step of including the active spreadsheet, as we did in the previous two examples, is unnecessary. (The system knows that the active spreadsheet is the one that contains the active sheet.)

var ActiveSheetInWB = SpreadsheetApp.getActiveSheet().getName();
// Gets the *name* of the sheet, as it shows on that sheet's tab.

var sheet = SpreadsheetApp.getActiveSheet();
var ActiveSheetInWB = sheet.getName();
// Shortens the long "SpreadsheetApp.getActiveSheet()" to a short reference to save typing in subsequent uses. Otherwise identical to above example.

Мне кажется, я наконец-то понял это ...

0 голосов
/ 01 марта 2019

«Spreadsheet.App» должно быть «SpreadsheetApp».

Дополнительные работающие перестановки:

Logger.log("We're in the function.");
var ss = SpreadsheetApp.getActiveSheet();
var valueOfCell = ss.getRange(1,1).getDisplayValue;

и

Logger.log("We're in the function.");
var valueOfCell = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(1,2).getDisplayValue();

и

Logger.log("We're in the function.");
var valueOfCell = SpreadsheetApp.getActiveSheet().getRange(1,2).getDisplayValue();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...