Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //друзья, привет, вам нужно заполнить только строки 4,5,6,11
- //если будут вопросы, то приходите
- const dateColumn = 1;
- const workSheetName = 'Ежедневный отчет';
- const protectRangeName = 'закрытые дни';
- //кому разрешим редактировать защищенный диапазон
- //через запятую перечисляйте емейлы других сотрудников,
- //себя можно не добавлять
- const editors = [];
- function closeRows() {
- const ss = SpreadsheetApp.getActive();
- const date = new Date((new Date).getTime() - 1000*60*60*24);
- const sheet = ss.getSheetByName(workSheetName);
- delProtection(sheet, protectRangeName);
- createProtection([sheet.getRange(2, 1, findRow(sheet, dateColumn)-1, sheet.getMaxColumns())], [protectRangeName]);
- }
- function findRow(sh, column) {
- const data = sh.getDataRange().getValues();
- const date = new Date((new Date).getTime() - 1000*60*60*24);
- return Math.max(...(data.map((g, i) => g[column-1] && g[column-1] <= date ? ++i : '')));
- }
- function delProtection(sheet, name) {
- var protections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE);
- for (var i = 0; i < protections.length; i++) {
- var protection = protections[i];
- if (protection.canEdit()) {
- protection.getDescription() == name ? protection.remove() : '';
- }
- }
- }
- function createProtection(range, names) {
- var me = Session.getEffectiveUser();
- range.map((rng, i) => {
- var protection = rng.protect().setDescription(names[i]);
- protection.removeEditors(protection.getEditors());
- protection.canDomainEdit() ? protection.setDomainEdit(false) : '';
- protection.addEditors([me].concat(editors));
- })
- }
- function onOpen(e){
- SpreadsheetApp.getUi()
- .createMenu("🐽 скрипты 🐽")
- .addItem("запустить скрипт закрытия диапазонов вручную", "closeRows")
- .addToUi();
- }
Add Comment
Please, Sign In to add comment