I'm trying to upload a csv file from an html service in google sheets, and after some research I found some code which seemed to be working at the time:
html service call:
function importAnalysis() {
var html = HtmlService.createHtmlOutputFromFile('Import')
.setWidth(1524)
.setHeight(800);
SpreadsheetApp.getUi()
.showModalDialog(html, 'Import d\'analyse');
}
html template:
<!DOCTYPE html>
<html>
<body>
<form>
<input type="file" name="analysisCsv" accept=".csv">
<input type="button" onclick="google.script.run.processForm(this.parentNode);">
</form>
</body>
</html>
gs file (I commented further code to isolate the source of the problem):
function processForm(form) {
let fileBlob=form.analysisCsv;
// sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Table_Analysis");
// let lastRow = sheet.getLastRow();
// let values = []
// let rows = fileBlob.contents.split('\n');
// for(let r=0; r<rows.length; ++r){
// values.push( rows[r].split(';') );
// }
// for (var i = 0; i < values.length; i++) {
// sheet.getRange(lastRow+i+1, 1, 1, values[i].length).setValues(new Array(values[i]));
// }
}
Problem is I get an error 400 on processForm function: "Failed to load resource: the server responded with a status of 400 ()"
Do you know what's wrong with my code, or another way to upload csv content in my sheet?
receiveForm?Open the Script Editor. In the top menu, select View > Show manifest file. In the files list, open appsscript.json. Replace "runtimeVersion": "V8" with "runtimeVersion": "STABLE" Save.