【发布时间】:2020-02-26 14:50:53
【问题描述】:
我正在尝试从 google 表格中的 html 服务上传 csv 文件,经过一番研究,我发现了一些当时似乎可以工作的代码:
html服务调用:
function importAnalysis() {
var html = HtmlService.createHtmlOutputFromFile('Import')
.setWidth(1524)
.setHeight(800);
SpreadsheetApp.getUi()
.showModalDialog(html, 'Import d\'analyse');
}
html 模板:
<!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 文件(我注释了更多代码以隔离问题的根源):
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]));
// }
}
问题是我在 processForm 函数上收到错误 400: "加载资源失败:服务器响应状态为 400()"
您知道我的代码有什么问题,或者以其他方式在我的工作表中上传 csv 内容吗?
【问题讨论】:
-
您可以尝试将函数名称重命名为
receiveForm之类的名称吗? -
尝试使用类似 google.script.run.proccessForm(this.parentNode)
-
能否请您尝试使用 Apps Script 的 STABLE 版本而不是 V8,以防万一出现问题,让我知道它是如何解决的?要实现这一点,请按照以下步骤操作:
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. -
当我将 "V8" 更改为 "STABLE" 时,我收到一个错误 "Missing ; sign before instruction" 并且我无法跟踪它的来源,html 根本不显示。
标签: forms google-apps-script file-upload