Created
October 24, 2025 16:41
-
-
Save ShilGen/eecda25f2befbb02a911db52a79115b1 to your computer and use it in GitHub Desktop.
Функция создаёт по шаблону листы
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function createSheetsFromTemplate() { | |
| var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
| var templateSheet = ss.getSheetByName('Шаблон'); | |
| var dataSheet = ss.getSheetByName('Sheet3'); | |
| if (!templateSheet) { | |
| Logger.log('Лист "Шаблон" не найден!'); | |
| return; | |
| } | |
| if (!dataSheet) { | |
| Logger.log('Лист "Sheet3" не найден!'); | |
| return; | |
| } | |
| // Получаем названия из диапазона A1:A75 | |
| var names = dataSheet.getRange('A1:A75').getValues(); | |
| // Создаем листы | |
| for (var i = 0; i < names.length; i++) { | |
| var sheetName = names[i][0]; | |
| // Пропускаем пустые ячейки | |
| if (sheetName === '' || sheetName === null) { | |
| continue; | |
| } | |
| // Проверяем, существует ли уже лист с таким именем | |
| var existingSheet = ss.getSheetByName(sheetName); | |
| if (existingSheet) { | |
| Logger.log('Лист "' + sheetName + '" уже существует, пропускаем.'); | |
| continue; | |
| } | |
| // Копируем шаблон | |
| var newSheet = templateSheet.copyTo(ss); | |
| newSheet.setName(sheetName); | |
| Logger.log('Создан лист: ' + sheetName); | |
| } | |
| Logger.log('Готово! Листы созданы.'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment