I want to include csv in my spreadsheet with UTF-8

Asked 1 years ago, Updated 1 years ago, 72 views

SHIFT-JIS saves the local CSV file, so it gets garbled when you import it into Google spreadsheet.

I would like to add a code to the following GAS script that you told me in the related question I asked you before, and would it be possible to do so?

function showDialog(){
  varhtml=HtmlService.createHtmlOutputFromFile('dialog');
  SpreadsheetApp.getUi().showModalDialog(html, "CSV Upload";
}

function uploadCsv(form){  
  var blob=form.myFile;
  varcsvText=blob.getDataAsString();    
  values = Utilities.parseCsv(csvText);
  SpreadsheetApp.getActiveSheet().getRange(1,1, values.length, values[0].length).setValues(values);
}

It would be very helpful if anyone knows.
Thank you for your cooperation.

google-apps-script google-spreadsheet

2022-09-30 16:22

1 Answers

All I had to do was set shift-jis for getDataAsString...
I was able to confirm the operation with the following code.
We have disabled Apps Script runtime.

function uploadCsv(form){
    var blob=form.myFile;
    varcsvText=blob.getDataAsString('shift-jis');
    values = Utilities.parseCsv(csvText);
    SpreadsheetApp.getActiveSheet().getRange(1,1, values.length, values[0].length).setValues(values);
}


2022-09-30 16:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.