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

后端 未结 3 726
忘了有多久
忘了有多久 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:52

    I had the same requirement and the same problem with a csv file. What I did may be a workaround but worked at least fine for me.

    The "�" may actually be any type of ASCII character that is not recognized so in my case searching for "\uFFFD" did not solve the problem. So what I did is basically convert the payload in binary data. There I managed to notice that between all characters a NULL was being delivered (ASCII Code 0). This was in my case the �. So what I did is rebuild the byte array without the 0s and then copy it in the spreadsheet again.

    var response = UrlFetchApp.fetch(theUrl);
    var payload = response.getContentText();
    //Get byte Array 
    var bytes= response.getContent();
    var myArray = [];
    //Build byte array without the faulty characters
    for ( var i =1 ; i

    This script in my case also works fine if I am importing numbers and using them in formulas.

提交回复
热议问题