How do I fix charset problems in .gs script?

后端 未结 1 995
梦如初夏
梦如初夏 2021-02-06 13:05

I have a problem with charsets.

I parsed a csv file in google-app-engine and I\'m posting to an uiapp table. But I checked special characters like áéíóú and those are

相关标签:
1条回答
  • 2021-02-06 13:59

    I found it, we need to get the content of the file first with a Blob object. This function is the one I use to parse some csv info into an array:

    function parsedCSV(){
      
     //searching the file. This gets only one file in var origen
      var listaArchivos = DocsList.getFolderById('XXXXXXX').getFiles()
      
      for (var i = 0; i < listaArchivos.length; i++) {
        if (listaArchivos[i].getName() == 'baul.csv'){
          var origen = listaArchivos[i];
      };
    }
    
    // HERE IS THE GOOD DEFINITION OF CHAR:
    var texto2= origen.getBlob().getDataAsString('ISO-8859-1');
    // I put all the corrected text in an array
    
    var arra = Utilities.parseCsv(texto2,";");
    return(arra);
    }
    

    This is the solved thing: https://script.google.com/macros/s/AKfycbyHa-bLWBHBr3qifbvzxecqGgGUYX8mhyo-TKoyfGvy/exec

    The trick:

    var textVariableName = fileObjectVariableName.getBlob().getDataAsString('ISO-8859-1');
    
    0 讨论(0)
提交回复
热议问题