Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用谷歌表单提交一张图片_Javascript_Google Apps Script - Fatal编程技术网

Javascript 用谷歌表单提交一张图片

Javascript 用谷歌表单提交一张图片,javascript,google-apps-script,Javascript,Google Apps Script,我已经阅读了另外两个关于将图像上传到谷歌表单的问题,但这对我来说仍然不起作用,我也不知道我错在哪里。 以下是脚本: var submissionSSKey = '1GjxpOgViIajIvDaSTMB5MlYa0ZSxgGa0izQSNZB_cEU'; var docurl = 'https://docs.google.com/document/d/1bwbKztm311K7rdbrzfzLG6ACs8n4nd4LaJ67L3whsfs/' var listitems = ['

我已经阅读了另外两个关于将图像上传到谷歌表单的问题,但这对我来说仍然不起作用,我也不知道我错在哪里。

以下是脚本:

var submissionSSKey = '1GjxpOgViIajIvDaSTMB5MlYa0ZSxgGa0izQSNZB_cEU';
var docurl =     'https://docs.google.com/document/d/1bwbKztm311K7rdbrzfzLG6ACs8n4nd4LaJ67L3whsfs/'
var listitems = ['Select a category','Portrait','Landscape','Nude','Night shots','Nature','Various']
var Panelstyle = {'background':'#dddddd','padding':'40px','borderStyle':'solid','borderWidth':'10PX','borderColor':'#bbbbbb'}

function doGet() {
  var app = UiApp.createApplication().setTitle('Photography contest').setStyleAttribute('padding','50PX');
  var panel = app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(400, 200);
  var title = app.createHTML('<B>Photography contest</B>').setStyleAttribute('color','grey').setStyleAttribute('fontSize','25PX');
  var grid = app.createGrid(6,2).setId('grid');
  var list1 = app.createListBox().setName('list1').setWidth('130');
   for(var i in listitems){list1.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, 'Name')
  .setWidget(2, 1, Textbox1.addClickHandler(cliHandler2))
  .setText(3, 0, 'Email')
  .setWidget(3, 1, email)
  .setText(4, 0, 'Image File')
  .setWidget(4, 1, upLoad.addChangeHandler(cliHandler2))
  .setWidget(5, 0, submitButton)
  .setWidget(5, 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 ListVal = e.parameter.list1;
  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, 4).setValues([[ListVal,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 : '+ListVal,'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
} 
var submissionsKey='1GjxpOgViIajIvDaSTMB5MlYa0ZSxgGa0izQSNZB_cEU';
var docurl=https://docs.google.com/document/d/1bwbKztm311K7rdbrzfzLG6ACs8n4nd4LaJ67L3whsfs/'
var listitems=[“选择类别”、“肖像”、“风景”、“裸体”、“夜景”、“自然”、“各种”]
var Panelstyle={'background':'ddddddddd','padding':'40px','borderStyle':'solid','borderWidth':'10PX','borderColor':'bbbbbbbb'}
函数doGet(){
var app=UiApp.createApplication().setTitle('Photography contest').setStyleAttribute('padding','50PX');
var panel=app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(400200);
var title=app.createHTML('Photography contest')。setStyleAttribute('color','grey')。setStyleAttribute('fontSize','25PX');
var grid=app.createGrid(6,2).setId('grid');
var list1=app.createListBox().setName('list1').setWidth('130');
对于(listitems中的变量i){list1.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('Submit');
var warning=app.createHTML('请填写所有字段').setStyleAttribute('背景','#bbbbbb').setStyleAttribute('字体大小','18px');
//文件上传
var cliHandler2=app.createClientHandler()
.validateLength(文本框1,1,40)。validateNotMatch(列表1,“选择类别”)。validateEmail(电子邮件)。validateNotMatch(上传,'FileUpload')
.forTargets(submitButton).setEnabled(true)
.forTargets(警告).setHTML('现在可以提交表单了').setStyleAttribute('背景','#99FF99').setStyleAttribute('字体大小','12px');
//表格上项目的网格布局
setWidget(0,1,标题)
.setText(1,0,“类别”)
.setWidget(1,1,list1.addClickHandler(cliHandler2))
.setText(2,0,'Name')
.setWidget(2,1,Textbox1.addClickHandler(cliHandler2))
.setText(3,0,“电子邮件”)
.setWidget(3,1,电子邮件)
.setText(4,0,“图像文件”)
.setWidget(4,1,upLoad.addChangeHandler(cliHandler2))
.setWidget(5,0,submitButton)
.setWidget(5,1,警告);
var cliHandler=app.createClientHandler().forTargets(警告).setHTML('文件上载时请稍候').setStyleAttribute('背景','黄色');
submitButton.addClickHandler(cliHandler).setEnabled(false);
面板。添加(网格);
应用程序添加(面板);
返回应用程序;
}
函数doPost(e){
var app=UiApp.getActiveApplication();
var ListVal=e.parameter.list1;
var textVal=e.parameter.TB1;
var Email=e.parameter.mail;
var fileBlob=e.parameter.uploadedFile;
var blob=fileBlob.setContentTypeFromExtension()
var img=DocsList.createFile(blob);
试一试{
var folder=DocsList.getFolder('photos');
}catch(e){DocsList.createFolder('photos');var folder=DocsList.getFolder('photos')}
img.addToFolder(文件夹);
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,4)。设置值([[ListVal,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()+”);
表1.setRowHeight(最后一行+1,80);
var GDoc=DocumentApp.openByUrl(docurl)
GDoc.appendTable([['Category:'+ListVal,'Name:'+textVal,'Email:'+Email]]))
var inlineI=GDoc.appendImage(img);
var width=inlineI.getWidth();
var newW=宽度;
var height=inlineI.getHeight();
var newH=高度;
var比率=宽度/高度;
Logger.log('w='+宽度+'h='+高度+'比率='+比率);
如果(宽度>640){
newW=640;
newH=parseInt(newW/比率);
}
inlineI.setWidth(newW).setHeight(newH)
GDoc.appendParagation('图像大小:'+width+'x'+height+'(最终)调整为'+newW+'x'+newH+'进行预览('+weight+'kB');
GDoc.appendHorizontalRule();
GDoc.saveAndClose();
app.add(app.createLabel(‘感谢您提交’);
返回应用程序
} 

此外,我不需要将图像上传到文档(只是工作表)的功能,但我想知道添加其他问题的基础知识。

桑迪的评论是正确的,切换到HTML服务可能比使用不推荐的UiApp服务更好(尽管它目前仍在工作)。 无论如何,您显示的代码使用DocsList,而这一个实际上已经死了;-)

下面是一个更新的代码,保持你的第一行ID和简单的pste的其余部分

function doGet() {
  var app = UiApp.createApplication().setTitle('Photography contest').setStyleAttribute('padding','50PX');
  var panel = app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(400, 200);
  var title = app.createHTML('<B>Photography contest</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 Textbox1 = app.createTextBox().setWidth('150px').setName('TB1');
  var email = app.createTextBox().setWidth('150px').setName('mail');
  var upLoad = app.createFileUpload().setName('uploadedFile');
  var upLoad1 = app.createFileUpload().setName('uploadedFile1');
  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');


  var cliHandler3 = app.createClientHandler()
  .validateNotMatches(upLoad1, '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, 'Name')
      .setWidget(2, 1, Textbox1.addClickHandler(cliHandler2))
      .setText(3, 0, 'Email')
      .setWidget(3, 1, email)
      .setText(4, 0, 'Image File')
      .setWidget(4, 1, upLoad.addChangeHandler(cliHandler2))
      .setWidget(5, 1, upLoad1.addChangeHandler(cliHandler3))
      .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();
  Logger.log(JSON.stringify(e));
  var ListVal = e.parameter.list1;
  var textVal = e.parameter.TB1;
  var Email = e.parameter.mail;
  var fileBlob1 = e.parameter.uploadedFile;
  var blob1 = fileBlob1.setContentTypeFromExtension()
  var img1 = DriveApp.createFile(blob1);
  var fileBlob2 = e.parameter.uploadedFile1;
  var blob2 = fileBlob2.setContentTypeFromExtension()
  var img2 = DriveApp.createFile(blob2);
  try{
  var folder = DriveApp.getFoldersByName('photos').next();
  }catch(e){DriveApp.createFolder('photos');var folder = DriveApp.getFoldersByName('photos').next()}
  folder.addFile(img1);
  DriveApp.getRootFolder().removeFile(img1);
  folder.addFile(img2);
  DriveApp.getRootFolder().removeFile(img2);
  var weight1 = parseInt(img1.getSize()/1000);
  var weight2 = parseInt(img2.getSize()/1000);
  var sheet = SpreadsheetApp.openById(submissionSSKey).getSheetByName('Sheet1');
  var lastRow = sheet.getLastRow();
  var targetRange = sheet.getRange(lastRow+1, 1, 1, 5).setValues([[ListVal,textVal,Email,"https://drive.google.com/uc?export=view&id="+img1.getId(),"https://drive.google.com/uc?export=view&id="+img2.getId()]]);
  var image1Insert = sheet.getRange(lastRow+1, 6).setFormula('=image("https://drive.google.com/uc?export=view&id='+img1.getId()+'")');
  var image2Insert = sheet.getRange(lastRow+1, 7).setFormula('=image("https://drive.google.com/uc?export=view&id='+img2.getId()+'")');
  sheet.setRowHeight(lastRow+1, 80);
  var GDoc = DocumentApp.openByUrl(docurl)
  GDoc.appendTable([['Category : '+ListVal,'Name : '+textVal,'Email : '+Email]])
  var inlineI = GDoc.appendImage(img1);
  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 ('+weight1+' kB)   ');
  var inlineI = GDoc.appendImage(img2);
  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 ('+weight2+' kB)   ');
  GDoc.appendHorizontalRule();
  GDoc.saveAndClose();
  app.add(app.createLabel('Thank you for submitting'));
  return app
}
函数doGet(){
var app=UiApp.createApplication().setTitle('Photography contest').setStyleAttribute('padding','50PX');
var panel=app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(400200);
var title=app.createHTML('Photography contest')。setStyleAttribute('color','grey')。setStyleAttribute('fontSize','25PX');
var grid=app.createGrid(7,2).setId('grid');
var list1=app.createListBox().setName('list1').setWidth('130');
对于(listitems中的变量i){list1.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 upLoad1=app.createFileUpload().setName('uploadedFile1');
var submitButton=app.createSubmitButton('Submit');
var warning=app.createHTML('请填写所有字段').setStyleAttribute('背景','#bbbbbb').setStyleAttribute('字体大小','18px');
//文件上传
var cliHandler2=app.createClientHandler()
.验证长度(Tex)