我有这个谷歌应用程序脚本应该
除了第3步之外一切顺利,其中更新的单元格始终是第一张纸中的单元格A1。但光标在另一个单元格的第3页上。
function onOpen(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var menuEntries = [];
menuEntries.push({name: "File...", functionName: "doGet"});
ss.addMenu("Attach ...", menuEntries);
}
function doGet(e) {
var app = UiApp.createApplication().setTitle("Attach file to sheet");
var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
var formContent = app.createVerticalPanel();
form.add(formContent);
formContent.add(app.createFileUpload().setName('thefile'));
formContent.add(app.createSubmitButton('Submit'));
app.add(form);
SpreadsheetApp.getActiveSpreadsheet().show(app);
return app;
}
function doPost(e) {
var fileBlob = e.parameter.thefile;
var doc = DocsList.getFolderById('0B0uw1JCogWHuc29FWFJMWmc3Z1k').createFile(fileBlob);
var app = UiApp.getActiveApplication();
var label = app.createLabel('file uploaded successfully');
var value = '=hyperlink("' + doc.getUrl() + '","' + doc.getName() + '")'
app.add(label);
app.close();
SpreadsheetApp.getActiveSheet().getActiveCell().setValue(value);
return app;
}
我在doPost()函数之外尝试了SpreadsheetApp.getActiveSheet().getActiveCell().setValue(value);
,这在正常上下文中调用时有效。我在这里缺少什么?
答案 0 :(得分:0)
从this answer判断,无法从doPost
函数中获取当前的电子表格/单元格,我的工作方式是通过doGet
函数获取它隐藏的字段并通过表单传递。完整的工作示例here。