Advertisement
Namokonov

Untitled

Aug 28th, 2020 (edited)
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dlt(){
  2.  
  3.   const ss = SpreadsheetApp.getActive();
  4.   const sh = ss.getSheetByName('DELETE EMPTY');
  5.   const urlRange = sh.getRange("A:C");
  6.   const d = urlRange.getValues()
  7.  
  8.   d.map((url, i) => {
  9.      if(url[0] && i > 0){    
  10.         const ss0 = SpreadsheetApp.openByUrl(url[0]);
  11.         ss0.getSheets().forEach(s => {
  12.           delete_all_empty_rows_sheet(s, url[1]);
  13.           delete_all_empty_columns(s, url[2]);
  14.         })
  15.   }
  16. })
  17. }
  18.  
  19. function delete_all_empty_rows_sheet(sheet, q){
  20.   const frozen_rows = sheet.getFrozenRows();
  21.   const lr = sheet.getLastRow();
  22.   const used_row = lr <= frozen_rows ? frozen_rows + 1 : lr ? lr : 1;
  23.  
  24.   const all_row = sheet.getMaxRows() - q;
  25.   if(used_row < all_row){sheet.deleteRows(used_row + 1, all_row - used_row)};
  26.   if(used_row > all_row){sheet.insertRows(all_row + q, used_row - all_row)};
  27.  
  28.  
  29.  
  30. }
  31.  
  32. function delete_all_empty_columns(sheet, q){
  33.  
  34.   const frozen_cols = sheet.getFrozenColumns();
  35.   const lc = sheet.getLastColumn();
  36.   const used_col = lc <= frozen_cols ? frozen_cols + 1 : lc ? lc : 1;
  37.    
  38.   const all_col = sheet.getMaxColumns() - q;
  39.   if(used_col < all_col){sheet.deleteColumns(used_col + 1, all_col-  used_col)};
  40.   if(used_col > all_col){sheet.insertColumns(all_col + q, used_col - used_col)};
  41.  
  42. }
  43.  
  44. function onOpen(e){
  45.   SpreadsheetApp.getUi()
  46.   .createMenu("скрипты от @google_sheets")
  47.   .addItem("удаляем ячейки / столбцы", "dlt")
  48.   .addSeparator()
  49. .addToUi();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement