Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function dlt(){
- const ss = SpreadsheetApp.getActive();
- const sh = ss.getSheetByName('DELETE EMPTY');
- const urlRange = sh.getRange("A:C");
- const d = urlRange.getValues()
- d.map((url, i) => {
- if(url[0] && i > 0){
- const ss0 = SpreadsheetApp.openByUrl(url[0]);
- ss0.getSheets().forEach(s => {
- delete_all_empty_rows_sheet(s, url[1]);
- delete_all_empty_columns(s, url[2]);
- })
- }
- })
- }
- function delete_all_empty_rows_sheet(sheet, q){
- const frozen_rows = sheet.getFrozenRows();
- const lr = sheet.getLastRow();
- const used_row = lr <= frozen_rows ? frozen_rows + 1 : lr ? lr : 1;
- const all_row = sheet.getMaxRows() - q;
- if(used_row < all_row){sheet.deleteRows(used_row + 1, all_row - used_row)};
- if(used_row > all_row){sheet.insertRows(all_row + q, used_row - all_row)};
- }
- function delete_all_empty_columns(sheet, q){
- const frozen_cols = sheet.getFrozenColumns();
- const lc = sheet.getLastColumn();
- const used_col = lc <= frozen_cols ? frozen_cols + 1 : lc ? lc : 1;
- const all_col = sheet.getMaxColumns() - q;
- if(used_col < all_col){sheet.deleteColumns(used_col + 1, all_col- used_col)};
- if(used_col > all_col){sheet.insertColumns(all_col + q, used_col - used_col)};
- }
- function onOpen(e){
- SpreadsheetApp.getUi()
- .createMenu("скрипты от @google_sheets")
- .addItem("удаляем ячейки / столбцы", "dlt")
- .addSeparator()
- .addToUi();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement