Google Apps脚本-使用一项功能删除所有工作表中的重复项 [英] Google Apps Script - Remove duplicates in all sheets with one function

查看:65
本文介绍了Google Apps脚本-使用一项功能删除所有工作表中的重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从另一个非常适合我的问题中获得了这段代码,但是我想获取它来删除每张工作表的重复项,而不仅仅是当前正在使用的工作表.这也适用于具有大量数据的大型电子表格,因此我也必须牢记最大6分钟的执行时间.有人有什么想法吗?

I have this code from another question that works perfectly for me, but I'd like to get it to remove the duplicates of every sheet and not just the currently active one. This is also for large spreadsheets with a lot of data, so I have to keep the 6min execution time maximum in mind as well. Does anyone have any ideas?

这是我的代码:

function removeDuplicates() {
  SpreadsheetApp.getActiveSheet().getDataRange().removeDuplicates();
}

推荐答案

以下修改如何?

SpreadsheetApp.getActiveSheet().getDataRange().removeDuplicates();

收件人:

SpreadsheetApp.getActiveSpreadsheet().getSheets().forEach(sheet => sheet.getDataRange().removeDuplicates());

  • 在此修改中,使用 getSheets()检索所有工作表,并使用 removeDuplicates()在循环中删除每张工作表的重复行.
    • In this modification, all sheets are retrieved with getSheets() and the duplicated rows of each sheet is removed with removeDuplicates() in a loop.
    • 这篇关于Google Apps脚本-使用一项功能删除所有工作表中的重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆