1

我在匹配数组中的字符串时遇到问题。B2 列:Lastrow 定义为数组,即“ID”。我正在尝试仅将唯一条目粘贴到 B2 列中不可用的谷歌工作表:Lastrow。问题是..当我运行代码时,它也允许在谷歌表中重复。

我通过工作表上的计数公式使用它,但这会导致最大代码运行时错误..因此我将范围用作数组。解决了错误但无法识别字符串是否唯一。

// Code: List Gmail Label to Google Sheet and save attachment to GDrive
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName('Summary');
var label = GmailApp.getUserLabelByName("Caterpiller Account");
var threads = label.getThreads();

function getEmails() {

    for (var i = 0; i < threads.length; i++) {
        var row = sheet.getLastRow() + 1;
        var message = threads[i].getMessages()[0];
        var ID   = message.getId();
        var fulldata = sheet.getRange('B2:B' + row).getValues();

        if (fulldata.indexOf(ID) == -1) {
            var messages=threads[i].getMessages();
            var listID=threads[i].getPermalink();
            var listdate=threads[i].getLastMessageDate();
            var message = threads[i].getMessages()[0];
            var attachment = message.getAttachments();
            var attachmentBlob = message.getAttachments()[0].copyBlob();
            var folder = DriveApp.getFolderById("1ilsecZOexqTWGfAMu5xJDx1pKh3z1US-");

            // EXTRACTOR CODE:
            for (var m=0; m < messages.length; m++) {
                sheet.getRange(row,1).setValue(messages[m].getSubject());
                sheet.getRange(row,2).setValue(ID);  
                sheet.getRange(row,3).setValue(listdate); // Value - Date

                for (var z=0; z<attachment.length; z++) {
                    var file = DriveApp.getFolderById("1ilsecZOexqTWGfAMu5xJDx1pKh3z1US-").createFile(attachmentBlob);
                    //Pending: Weblinkview (basically get permanent url of file) / Or self developed function that gets file through description (where description is email ID)
                }
                row++;
            }
        }
    }
}

预期:唯一条目和更快的代码运行时。实际:我很垃圾,代码时间仍然相同。

4

1 回答 1

-1
bool IsSame(string str,char arr[100])
{
    if(str.lenght!=strlen(arr))return false;
    for(int i=0;i<str.lenght;i++)
    {
        if(str[i]!=arr[i]) return false;
    }
    return true;
}
于 2019-01-28T10:21:29.143 回答