Google Apps Script Utilities.parseCsv() and replacement character - �

后端 未结 3 1320
余生分开走
余生分开走 2021-02-10 14:28

I\'m working on a project that involves a csv file in Google Drive that is updated with new data every minute or so.

I\'ve built a spreadsheet dashboard to make the dat

3条回答
  •  逝去的感伤
    2021-02-10 14:51

    Have you check the file charset? You can specify it when calling getDataAsString(charset). Try this:

    function importData() {
      var ss = SpreadsheetApp.getActive();
      var file = DriveApp.getFilesByName("Agent Performance.csv")
      var csv = file.next().getBlob().getDataAsString('ISO-8859-1'); //note the charset
      var csvData = Utilities.parseCsv(csv);
      //unless you csv has variable amount of columns per line, you should do this
      if(csvData.length > 0) {
        ss.getSheetByName('CSV Import TEST')
          .getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
      } else
        throw 'Blank file';
    }
    

提交回复
热议问题