如果BF中的数据相同,请删除重复行

发布于 2025-02-10 04:46:48 字数 968 浏览 0 评论 0原文

因此,对于此问题,我在AG列中有数据,我需要在BF行中删除所有行,并用重复的信息:

function urlsToSheets(){
    importData("https://hub.arcgis.com/datasets/d3cd48afaacd4913b923fd98c6591276_36.csv", "Pavement Condition");
}


function importData(url, sheetName) {
    let requiredColumns;
      if (url == "https://hub.arcgis.com/datasets/d3cd48afaacd4913b923fd98c6591276_36.csv"){
        requiredColumns = [0, 3, 11, 12, 13, 14, 30]; 
    const res = UrlFetchApp.fetch(url);
    const ar = Utilities.parseCsv(res.getContentText());
    const values = ar.map(r => requiredColumns.map(i => r[i]));
    const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
    sheet.clear();
    sheet.getRange(1, 1, values.length, values[0].length).setValues(values);
    // sheet.getDataRange().removeDuplicates("B:B","F:F");
}

实际上为5个URL和5个单独的单独纸编写了该脚本,但是我将其简化为一个URL/Sheet例子。

我知道我的删除重复项的语法是不正确的,但是我不确定这是单行类型的问题,还是我是否需要使用某种循环。

任何帮助都将受到赞赏。谢谢你!

So for this problem I have data in columns A-G and I need to remove entire rows with duplicate information in rows B-F:

function urlsToSheets(){
    importData("https://hub.arcgis.com/datasets/d3cd48afaacd4913b923fd98c6591276_36.csv", "Pavement Condition");
}


function importData(url, sheetName) {
    let requiredColumns;
      if (url == "https://hub.arcgis.com/datasets/d3cd48afaacd4913b923fd98c6591276_36.csv"){
        requiredColumns = [0, 3, 11, 12, 13, 14, 30]; 
    const res = UrlFetchApp.fetch(url);
    const ar = Utilities.parseCsv(res.getContentText());
    const values = ar.map(r => requiredColumns.map(i => r[i]));
    const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
    sheet.clear();
    sheet.getRange(1, 1, values.length, values[0].length).setValues(values);
    // sheet.getDataRange().removeDuplicates("B:B","F:F");
}

This script is actually written for 5 URLs and 5 Separate sheets, but I've simplified it for one URL/sheet in this example.

I know my syntax for removing duplicates is incorrect, but I'm not sure if this is a one-line type of problem or if I'll need to use a loop of some kind.

Any help is appreciated. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初与友歌 2025-02-17 04:46:48

sheet
    .getRange(1, 1, values.length, values[0].length)
    .setValues(values)
    .removeDuplicates([/*B*/2,3,4,5,6/*F*/])

As the docs say, use

sheet
    .getRange(1, 1, values.length, values[0].length)
    .setValues(values)
    .removeDuplicates([/*B*/2,3,4,5,6/*F*/])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文