我一直在使用示例代码,以允许用户以谷歌形式提交照片以更新到Google电子表格。 我正在使用Serge Insas的原始代码,我能够完全按照他的预期工作方式开展工作。 现在我正在尝试使用它来满足我的需求,只需要有一个以上的下拉列表,我需要捕获比原始代码允许的更多信息。 我对此非常陌生并通过反复试验做大部分工作。 我可以使用两个列表框显示表单,但两个列表框的下拉列表是相同的(List1)
这是我修改过的代码,它将在第二个列表框中发布所选内容但我需要显示list2中的项目。 任何帮助将不胜感激。
由于
var submissionSSKey = '0ArbqJejC7zBydGNUbVpwd2hrQ3RFY3VxZ0RCeU5aV3c';
var docurl = 'https://docs.google.com/document/d/13FWMTtzprlhN73cMp73zPtunsOcoAFO5PCROp1PHiv4/'
var listitems = ['Select a category', 'LKQ', 'AM', 'OEM']
var listitems2 = ['Select a category', 'Wrong Part', 'Poor Fit', 'Poor Quality']
var Panelstyle = {
'background': '#dddddd',
'padding': '40px',
'borderStyle': 'solid',
'borderWidth': '10PX',
'borderColor': '#bbbbbb'
}
function doGet() {
var app = UiApp.createApplication().setTitle('Parts Return Reasons').setStyleAttribute('padding', '50PX');
var panel = app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(400, 200);
var title = app.createHTML('<B>PartsReturnReasons</B>').setStyleAttribute('color', 'grey').setStyleAttribute('fontSize', '25PX');
var grid = app.createGrid(7, 2).setId('grid');
var list1 = app.createListBox().setName('list1').setWidth('130');
for (var i in listitems) {
list1.addItem(listitems[i])
}
var list2 = app.createListBox().setName('list2').setWidth('130');
for (var i in listitems2) {
list2.addItem(listitems[i])
}
var Textbox1 = app.createTextBox().setWidth('150px').setName('TB1');
var email = app.createTextBox().setWidth('150px').setName('mail');
var upLoad = app.createFileUpload().setName('uploadedFile');
var submitButton = app.createSubmitButton('<B>Submit</B>');
var warning = app.createHTML('Please fill in all fields').setStyleAttribute('background', '#bbbbbb').setStyleAttribute('fontSize', '18px');
//file upload
var cliHandler2 = app.createClientHandler()
.validateLength(Textbox1, 1, 40).validateNotMatches(list1, 'Select a category').validateEmail(email).validateNotMatches(upLoad, 'FileUpload')
.forTargets(submitButton).setEnabled(true)
.forTargets(warning).setHTML('Now you can submit your form').setStyleAttribute('background', '#99FF99').setStyleAttribute('fontSize', '12px');
//Grid layout of items on form
grid.setWidget(0, 1, title)
.setText(1, 0, 'Category')
.setWidget(1, 1, list1.addClickHandler(cliHandler2))
.setText(2, 0, 'Reason')
.setWidget(2, 1, list2.addClickHandler(cliHandler2))
.setText(3, 0, 'Name')
.setWidget(3, 1, Textbox1.addClickHandler(cliHandler2))
.setText(4, 0, 'Email')
.setWidget(4, 1, email)
.setText(5, 0, 'Image File')
.setWidget(5, 1, upLoad.addChangeHandler(cliHandler2))
.setWidget(6, 0, submitButton)
.setWidget(6, 1, warning);
var cliHandler = app.createClientHandler().forTargets(warning).setHTML('<B>PLEASE WAIT WHILE THE FILE IS UPLOADING<B>').setStyleAttribute('background', 'yellow');
submitButton.addClickHandler(cliHandler).setEnabled(false);
panel.add(grid);
app.add(panel);
return app;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
var ListVal1 = e.parameter.list1;
var ListVal2 = e.parameter.list2;
var textVal = e.parameter.TB1;
var Email = e.parameter.mail;
var fileBlob = e.parameter.uploadedFile;
var blob = fileBlob.setContentTypeFromExtension()
var img = DocsList.createFile(blob);
try {
var folder = DocsList.getFolder('photos');
} catch (e) {
DocsList.createFolder('photos');
var folder = DocsList.getFolder('photos')
}
img.addToFolder(folder);
img.removeFromFolder(DocsList.getRootFolder());
var weight = parseInt(img.getSize() / 1000);
var sheet = SpreadsheetApp.openById(submissionSSKey).getSheetByName('Sheet1');
var lastRow = sheet.getLastRow();
var targetRange = sheet.getRange(lastRow + 1, 1, 1, 5).setValues([
[ListVal1, ListVal2, textVal, Email, "https://drive.google.com/uc?export=view&id=" + img.getId()]
]);
var imageInsert = sheet.getRange(lastRow + 1, 5).setFormula('=image("https://drive.google.com/uc?export=view&id=' + img.getId() + '")');
sheet.setRowHeight(lastRow + 1, 80);
var GDoc = DocumentApp.openByUrl(docurl)
GDoc.appendTable([
['Category : ' + ListVal1, ListVal2, 'Name : ' + textVal, 'Email : ' + Email]
])
var inlineI = GDoc.appendImage(img);
var width = inlineI.getWidth();
var newW = width;
var height = inlineI.getHeight();
var newH = height;
var ratio = width / height;
Logger.log('w=' + width + 'h=' + height + ' ratio=' + ratio);
if (width > 640) {
newW = 640;
newH = parseInt(newW / ratio);
}
inlineI.setWidth(newW).setHeight(newH)
GDoc.appendParagraph('IMAGE size : ' + width + ' x ' + height + ' (eventually) resized to ' + newW + ' x ' + newH + ' for PREVIEW (' + weight + ' kB) ');
GDoc.appendHorizontalRule();
GDoc.saveAndClose();
app.add(app.createLabel('Thank you for submitting'));
return app;
}
答案 0 :(得分:2)
你在代码中犯了一个简单的错字。
for (var i in listitems2) { list2.addItem(listitems2[i])
您必须在正确的源数组
中获取列表项