我必须承认,我无法从头开始编写所需的解决方案,通常我会操纵可用于解决我经常遇到的问题的代码。运行我正在使用的代码
时出现的问题UiApp已被弃用。请改用HtmlService。
我查看了Htmlservice文档,但不知道如何将整个UIapp代码转换为功能性html代码。如果有人已经解决了由于弃用(UIapp)而引起的文件附件问题,那么将对您有很大的帮助。
或者,如果有人可以向我建议可以替代的任何内容,请告知我。
// upload document into google spreadsheet
// and put link to it into current cell
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("upload attachment into Google Drive");
SpreadsheetApp.getActiveSpreadsheet().show(app);
var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
var formContent = app.createVerticalPanel();
form.add(formContent);
formContent.add(app.createFileUpload().setName('thefile'));
// these parameters need to be passed by form
// in doPost() these cannot be found out anymore
formContent.add(app.createHidden("activeCell", SpreadsheetApp.getActiveRange().getA1Notation()));
formContent.add(app.createHidden("activeSheet", SpreadsheetApp.getActiveSheet().getName()));
formContent.add(app.createHidden("activeSpreadsheet", SpreadsheetApp.getActiveSpreadsheet().getId()));
formContent.add(app.createSubmitButton('Submit'));
app.add(form);
SpreadsheetApp.getActiveSpreadsheet().show(app);
return HtmlService.createHtmlOutputFromFile('Index');
}
function doPost(e) {
var app = UiApp.getActiveApplication();
app.createLabel('saving...');
var fileBlob = e.parameter.thefile;
var doc = DriveApp.getFolderById('enterfolderId').createFile(fileBlob);
var label = app.createLabel('file uploaded successfully');
// write value into current cell
var value = 'hyperlink("' + doc.getUrl() + '";"' + doc.getName() + '")'
var activeSpreadsheet = e.parameter.activeSpreadsheet;
var activeSheet = e.parameter.activeSheet;
var activeCell = e.parameter.activeCell;
var label = app.createLabel('file uploaded successfully');
app.add(label);
SpreadsheetApp.openById(activeSpreadsheet).getSheetByName(activeSheet).getRange(activeCell).setFormula(value);
app.close();
return app;
}
答案 0 :(得分:-2)
几秒钟前我遇到了这个问题,我正在使用Mac计算机。我在Google chrome上打开了我的APi,很遗憾看到此'UiApp已被弃用。请改为使用HtmlService。一个简单的答案:切换到Safari浏览器在Safari浏览器中打开我的脚本后,问题解决了:)