I want to import the csv file on my Google drive to Google Sheet, but there is a problem with my Google script.
I'd like to get some help.
It's got a strange value:
This is the xlsx data I need to Import google sheet:
My script:
function ExportRange() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
today = mm + '/' + dd;
Logger.log(today);
for (var i = 0; i <= 0; i++) {
var file = DriveApp.getFilesByName(today + '_' + i + '.csv');
Logger.log("today file count :" + today + '_' + i + '.csv');
var spreadsheet = SpreadsheetApp.getActive();
var test;
var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var yourNewSheet = activeSpreadsheet.getSheetByName(today + '_' + i);
if (yourNewSheet != null) {
activeSpreadsheet.deleteSheet(yourNewSheet);
}
yourNewSheet = activeSpreadsheet.insertSheet();
yourNewSheet.setName(today + '_' + i);
var csv = file.next().getBlob().getDataAsString();
var csvData = Utilities.parseCsv(csv);
yourNewSheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
}