使用 removeDuplicates() 方法去除重複資料列
function myFunction() { var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var sheet = spreadsheet.getSheetByName("aaa"); sheet.appendRow(["aa", "bb", "cc"]); sheet.appendRow(["aa", "bb", "cc"]); sheet.appendRow(["aa", "bb", "cc"]); sheet.appendRow(["aa1", "bb", "cc"]); sheet.appendRow(["aa1", "bb", "cc"]); sheet.appendRow(["aa1", "bb", "cc"]); var range = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns()).activate(); //移除重複資料(每一欄都相同的資料列) range.removeDuplicates().activate(); //移除重複資料(B、C 欄相同的資料列) //range.removeDuplicates([2, 3]).activate(); }
參考:
- https://developers.google.com/apps-script/reference/spreadsheet/range?hl=zh-tw#removeDuplicates()
Class Range | Apps Script | Google Developers
沒有留言:
張貼留言