【发布时间】:2021-05-29 19:46:06
【问题描述】:
我想做什么
- 从 CSV 文件中获取数据(字符集:Shift-JIS)
- 将字符集转换为 UTF-8
- 将值设置到 Google 电子表格中
我在第 2 步遇到问题。
问题
我在将 Shift-JIS CSV 转换为 UTF-8 CSV 时遇到问题。
Google 电子表格中的字符串都是乱码。
这是我的 Google 电子表格的代码和屏幕截图:
function myFunction() {
const fileId = 'xxxxxx' // Shift-JIS CSV file's ID
const blob = DriveApp.getFileById(fileId).getBlob();
const csv = blob.getDataAsString();
const newBlob = Utilities.newBlob('', MimeType.CSV).setDataFromString(csv, 'UTF-8');
const newCSV = newBlob.getDataAsString();
const values = Utilities.parseCsv(newCSV);
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1, 1, values.length, values[0].length).setValues(values);
}
【问题讨论】:
标签: csv google-apps-script google-sheets utilities