Предотвратить значение изменения от Google Sheet ArrayformulaJavascript

Форум по Javascript
Ответить
Anonymous
 Предотвратить значение изменения от Google Sheet Arrayformula

Сообщение Anonymous »

Я пытаюсь «заморозить» (сделать постоянным) определенные строки в моем листе Google. Эти ряды получают свои данные из другой электронной таблицы с использованием Imprange. Моя цель состоит в том, чтобы эти конкретные строки сохраняли свои текущие значения, даже если исходные данные в другой таблице изменяются. Когда я пытаюсь «заморозить» строку (заменив сценарий заменить его формулу статическим значением), Arrayformula перестает работать. Он бросает ошибку, потому что ему нужно, чтобы все его выходные ячейки были пустыми, а моя «замороженная» строка теперь занимает эти ячейки. < /P>
function freeze() {
var spreadsheet = SpreadsheetApp.getActive(); // Gets the active spreadsheet.
var ui = SpreadsheetApp.getUi(); // Gets the user interface environment for pop-up messages.

// Retrieves the range currently selected by the user.
var selectedRange = spreadsheet.getActiveRange();

// Checks if a range was actually selected.
if (!selectedRange) {
// Displays an error alert if no range is selected.
ui.alert('Error', 'No range selected. Please select a range on the sheet before running the script.', ui.ButtonSet.OK);
return; // Exits the function.
}

// Asks the user for confirmation before proceeding with the freeze operation.
var response = ui.alert(
'Freeze Values', // Title of the confirmation dialog.
'Confirm you want to freeze values in the selected range: ' + selectedRange.getA1Notation() + '?', // Message including the selected range.
ui.ButtonSet.YES_NO // Provides 'Yes' and 'No' buttons.
);

// Proceeds only if the user confirms by clicking 'Yes'.
if (response == ui.Button.YES) {
try {
// Copies the values from the selected range and pastes them back onto the same range.
// This effectively replaces any formulas with their static calculated values.
selectedRange.copyTo(selectedRange, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);

// Displays a success alert to the user.
ui.alert('Success', 'Values frozen for the range: ' + selectedRange.getA1Notation(), ui.ButtonSet.OK);

} catch (e) {
// Catches and handles any errors that might occur during the operation (e.g., invalid range).
ui.alert('Error', 'An error occurred during the operation: ' + e.message, ui.ButtonSet.OK);
}
} else {
// Displays an alert if the user cancels the operation.
ui.alert('Cancelled', 'Operation cancelled.', ui.ButtonSet.OK);
}
}
< /code>
Ошибка этой формулы: < /p>

ошибка < /p>
Результат массива не был расширен, поскольку он будет перезаписать данные в F19. < /p>
< /blockquote>

Подробнее здесь: https://stackoverflow.com/questions/796 ... rayformula
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»