Я пытаюсь «заморозить» (сделать постоянным) определенные строки в моем листе 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
Предотвратить значение изменения от Google Sheet Arrayformula ⇐ Javascript
Форум по Javascript
-
Anonymous
1749334756
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>
Подробнее здесь: [url]https://stackoverflow.com/questions/79657328/prevent-change-value-from-google-sheet-arrayformula[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия