我正在创建一个基本表单,该表单通过文本框和下拉列表获取用户输入,提交后将登录到电子表格。到目前为止,这工作正常。我想添加到表单中的是“文件上传”功能,它允许某人选择文件并在提交表单时上传文件,因为来自文本框和下拉列表的数据值被记录到电子表格中。我已经查看了以下链接https://developers.google.com/apps-script/class_fileupload但我很难将示例插入/添加到现有的 doGet 函数中。任何人都可以提供帮助或提供建议吗?这是到目前为止的 Google App 脚本代码。
*使用以下链接作为表单的基础: https ://sites.google.com/site/appsscripttutorial/advanced-examples/insert-data-in-sheet-using-ui-forms
// Script-as-app template.
var submissionSSKey = 'Spreadsheet Key goes Here';
function doGet() {
var app = UiApp.createApplication().setTitle('Loan Registration Processing');
var panel = app.createVerticalPanel();
var grid = app.createGrid(8,2).setId('loanGrid');
var loanTypeLabel = app.createLabel('Loan Type');
var loanList = app.createListBox().setName('Loan List').setWidth('120px').setName('LoanType');
loanList.addItem('Select Option');
loanList.addItem('FHA');
loanList.addItem('Convential');
loanList.addItem('VA');
loanList.addItem('Reverse');
loanList.addItem('HELOC');
var borrowerNameLabel = app.createLabel("Borrower's Name");
var borrowerTextbox = app.createTextBox().setWidth('150px').setName('borrower');
var loanAmountLabel = app.createLabel('Loan Amount');
var loanAmountTextbox = app.createTextBox().setWidth('150px').setName('amount');
var appDateLabel = app.createLabel('Loan Date');
var appDateTextbox = app.createTextBox().setWidth('150px').setName('date');
var lienPostition = app.createLabel('Lien Position');
var lienPos = app.createListBox().setName('Lien Position').setWidth('150px').setName('LienPosition');
lienPos.addItem('Select Option');
lienPos.addItem('1st');
lienPos.addItem('2nd');
var propertyType = app.createLabel('Property Type');
var propType = app.createListBox().setName('Property Type').setWidth('150px').setName('PropertyType');
propType.addItem('Select Option');
propType.addItem('1-4');
propType.addItem('Manufactured');
var submitButton = app.createButton('Submit');
//Grid layout of items on form
grid.setWidget(0, 0, loanTypeLabel)
.setWidget(0, 1, loanList)
.setWidget(1, 0, borrowerNameLabel)
.setWidget(1, 1, borrowerTextbox)
.setWidget(2, 0, loanAmountLabel)
.setWidget(2, 1, loanAmountTextbox)
.setWidget(3, 0, appDateLabel)
.setWidget(3, 1, appDateTextbox)
.setWidget(4, 0, lienPostition)
.setWidget(4, 1, lienPos)
.setWidget(5, 0, propertyType)
.setWidget(5, 1, propType)
.setWidget(6, 0, submitButton)
//Event Handler
var handler = app.createServerClickHandler('insertInSS');
handler.addCallbackElement(panel);
submitButton.addClickHandler(handler);
panel.add(grid);
app.add(panel);
return app;
}
//Function to insert data in the sheet on clicking the submit button
function insertInSS(e){
var app = UiApp.getActiveApplication();
var LoanType = e.parameter.LoanType;
var borrower = e.parameter.borrower;
var amount = e.parameter.amount;
var date = e.parameter.date;
var LienPosition = e.parameter.LienPosition;
var PropertyType = e.parameter.PropertyType;
//app.getElementById('info').setVisible(true).setStyleAttribute('color','red');
var sheet = SpreadsheetApp.openById(submissionSSKey).getActiveSheet();
var lastRow = sheet.getLastRow();
var targetRange = sheet.getRange(lastRow+1, 1, 1, 6).setValues([[LoanType,borrower,amount,date,LienPosition,PropertyType]]);
return app;
}