简体   繁体   中英

Error: getBlob is not defined when geting latest CSV file in a specified folder

I am trying to repurpose a scrcipt that gets all CSV files in a spicified folder to get only the lattest CSV file in a folder

Original from here Google Script to copy all csv files in a GDrive Folder as new sheets in existing 'master' Google sheet

I get the error Error: getBlob is not defined here let vs = Utilities.parseCsv(DriveApp.getFileById(arr[0].id),getBlob().getDataAsString());

What I have so far

How to correct the error?

Thanks

function runScript2() {
  const ss = SpreadsheetApp.getActive()
  const folder = DriveApp.getFolderById("1Hxxx");
  const files = folder.getFiles();
  const arr = [];

  while (files.hasNext()) {
    let file = files.next();  
 arr.push({name:file.getName(),id:file.getId(),mimetype:file.getMimeType(),date:file.getDateCreated()});
    //let fn = file.getName();
    //let fileID = file.getId();
    //let fileType = file.getMimeType();
  };
    //console.log(arr)
    arr.sort((a,b)=> {
      return new Date(b.date).valueOf() - new Date(a.date).valueOf();
    });
    //console.log(arr)

    let vs = Utilities.parseCsv(DriveApp.getFileById(arr[0].id),getBlob().getDataAsString());
    let sh = SpreadsheetApp.getActiveSheet();
    sh.clearContents();
    sh.getRange(1,1,vs.length, vs[0].length).setValues(vs);
}

I think you have a typo. Change the ,getBlob() to .getBlob()

let vs = Utilities.parseCsv(DriveApp.getFileById(arr[0].id),getBlob().getDataAsString());

To

let vs = Utilities.parseCsv(DriveApp.getFileById(arr[0].id).getBlob().getDataAsString());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM