谷歌脚本UI -阅读和张贴从电子表格,链接到填充的UI



我已经创建了一个UI,我想用它来读取和发布电子表格。现在,请忽略a栏中的链接格式。现在,它链接到一个表单。我想使用UI代替,并将删除引用链接的形式一旦我有这个设置。

这是当前的UI。

我希望最终结果是:1. 当提交新条目时,管理人员会收到一封带有链接的电子邮件。

  1. 该链接将打开UI

  2. 顶部(灰色)区域将根据ID号(A列)填充电子表格中的相关值。

  3. 底部区域将为空白,或者使用电子表格中存在的相关值填充。

  4. 用户将根据需要填写底部区域,并提交。

  5. 输入到UI中的数据将在正确的列中填充电子表格。

  6. 查看电子表格的用户将能够点击ID号码,并且它将拉出填充的UI。

这是很简单的只是使用表单,但我正在寻找更灵活的东西,所以我使用UI。

以下是我的问题:1. 我找不到一个简单、直接的脚本,它可以搜索一个值,并在找到该值后获取包含该值的行中的其余数据。◦我疯狂地寻找这个,每个人似乎都有不同的想法,但没有一个适合我正在寻找的。
  1. 我理解如何将值从UI传递到电子表格,但反之亦然。

  2. var formUrl = formResponse.toPrefilledUrl();工作相同的方式与UI,因为它与表单?如果没有,如何创建到预填充UI的链接?

UI的代码如下。是的,我知道现在的UI很难看。

任何和所有的帮助是非常感激的!我在这方面还是个新手,但是每天都在学习新的东西。

function doGet(e) {
  var complaintApp = UiApp.createApplication().setTitle("Complaint Follow-Up").setWidth(1100).setHeight(1000);
  //For pre-populating  
  var prePanel = complaintApp.createAbsolutePanel().setWidth('100%').setStyleAttributes({background: 'D8D8D8'})
  var infoGrid = complaintApp.createGrid(2, 6).setStyleAttributes({fontWeight: "bold", }).setWidth('100%');
  var idNum = complaintApp.createLabel('Complaint ID #:').setStyleAttributes({textAlign: 'right', float: 'left'});
  infoGrid.setWidget(0, 0, idNum);
  infoGrid.setWidget(0, 1, complaintApp.createTextBox().setName('ID').setId('ID').setStyleAttributes({float: 'left'}));
  infoGrid.setWidget(0, 2, complaintApp.createLabel('Submitted by:').setStyleAttributes({textAlign: 'right', margin: "0 auto"}));
  infoGrid.setWidget(0, 3, complaintApp.createTextBox().setName('subBy').setId('subBy').setStyleAttributes({margin: "0 auto"}));
  infoGrid.setWidget(0, 4, complaintApp.createLabel('Submitted at:').setStyleAttributes({textAlign: 'right'}));
  infoGrid.setWidget(0, 5, complaintApp.createTextBox().setName('subAt').setId('subAt').setStyleAttributes({float: 'left'}));
  infoGrid.setWidget(1, 2, complaintApp.createLabel('Time since complaint (in hours):').setStyleAttributes({textAlign: 'right'}));
  infoGrid.setWidget(1, 3, complaintApp.createTextBox().setName('timeSince').setId('timeSince').setWidth(50));
  var guestGrid = complaintApp.createGrid(2, 8).setStyleAttributes({fontWeight: "bold"}).setWidth('100%');
  guestGrid.setWidget(0, 0, complaintApp.createLabel('Guest name:').setStyleAttributes({textAlign: 'right'}));
  guestGrid.setWidget(0, 1, complaintApp.createTextBox().setName('gName').setId('gName'));
  guestGrid.setWidget(0, 2, complaintApp.createLabel('Room #:').setStyleAttributes({textAlign: 'right'}));
  guestGrid.setWidget(0, 3, complaintApp.createTextBox().setName('roomNum').setId('roomNum'));
  guestGrid.setWidget(0, 4, complaintApp.createLabel('Dates of Stay:').setStyleAttributes({textAlign: 'right', float: 'right'}));
  guestGrid.setWidget(0, 5, complaintApp.createTextBox().setName('arrDate').setId('arrDate').setStyleAttributes({float: 'right'}));
  guestGrid.setWidget(0, 6, complaintApp.createLabel(' - ').setStyleAttributes({margin: '0 auto'}));
  guestGrid.setWidget(0, 7, complaintApp.createTextBox().setName('depDate').setId('depDate').setStyleAttributes({float: 'right'}));
  guestGrid.setWidget(1, 0, complaintApp.createLabel('Email Address:').setStyleAttributes({textAlign: 'right'}));
  guestGrid.setWidget(1, 1, complaintApp.createTextBox().setName('email').setId('email'));
  guestGrid.setWidget(1, 2, complaintApp.createLabel('Phone Number:').setStyleAttributes({textAlign: 'right'}));
  guestGrid.setWidget(1, 3, complaintApp.createTextBox().setName('phone').setId('phone'));
  var complaintGrid = complaintApp.createGrid(2, 2).setStyleAttributes({fontWeight: "bold", margin: "0 auto"}).setWidth('100%');
  complaintGrid.setWidget(0, 0, complaintApp.createLabel('Complaint concerns:'));
  complaintGrid.setWidget(1, 0, complaintApp.createTextArea().setName('department').setId('department').setWidth(200));
  complaintGrid.setWidget(0, 1, complaintApp.createLabel('Complaint:'));
  complaintGrid.setWidget(1, 1, complaintApp.createTextArea().setName('complaint').setId('complaint').setWidth(800).setHeight(100).setStyleAttributes({overflow: "auto"}));
  var detailsGrid = complaintApp.createGrid(2, 6).setStyleAttributes({fontWeight: 'bold'}).setWidth('100%');
  detailsGrid.setWidget(0, 0, complaintApp.createLabel('First attempt at resolution by:').setStyleAttributes({textAlign: 'right'}));
  detailsGrid.setWidget(0, 1, complaintApp.createTextBox().setName('firstRes').setId('firstRes'));
  detailsGrid.setWidget(0, 2, complaintApp.createLabel('First attempt at resolution at:').setStyleAttributes({textAlign: 'right'}));
  detailsGrid.setWidget(0, 3, complaintApp.createTextBox().setName('firstTime').setId('firstTime'));
  detailsGrid.setWidget(0, 4, complaintApp.createLabel('Resolution provided:').setStyleAttributes({textAlign: 'right'}));
  detailsGrid.setWidget(0, 5, complaintApp.createTextArea().setName('resList').setId('resList'));
  detailsGrid.setWidget(1, 0, complaintApp.createLabel('Appeasement amount:').setStyleAttributes({textAlign: 'right'}));
  detailsGrid.setWidget(1, 1, complaintApp.createTextBox().setName('appeasement').setId('appeasement'));
  detailsGrid.setWidget(1, 2, complaintApp.createLabel('Guest mindset after initial resolution:').setStyleAttributes({textAlign: 'right'}));
  detailsGrid.setWidget(1, 3, complaintApp.createTextBox().setName('mindset').setId('mindset'));
  detailsGrid.setWidget(1, 4, complaintApp.createLabel('Is follow-up required?').setStyleAttributes({textAlign: 'right'}));
  detailsGrid.setWidget(1, 5, complaintApp.createTextBox().setName('followup').setId('followup'));
  var topPanel = complaintApp.createHorizontalPanel().setStyleAttributes({borderStyle: "groove", borderWidth: "2", borderColor: "threedface"}).setWidth('100%');
  var guestPanel = complaintApp.createCaptionPanel('Guest Information').setStyleAttributes({background: "#D8D8D8", fontWeight: 'bold'});
  var complaintPanel = complaintApp.createCaptionPanel('Complaint Information').setStyleAttributes({background: "#D8D8D8", fontWeight: 'bold', overflow: 'auto'});
  var detailsPanel = complaintApp.createCaptionPanel('Initial Resolution Attempt').setStyleAttributes({fontWeight: 'bold'});

  topPanel.add(infoGrid);
  guestPanel.add(guestGrid);
  complaintPanel.add(complaintGrid);
  detailsPanel.add(detailsGrid);
  prePanel.add(topPanel);
  prePanel.add(guestPanel);
  prePanel.add(complaintPanel);
  prePanel.add(detailsPanel);
  complaintApp.add(prePanel);
  //Take info
  var subPanel = complaintApp.createAbsolutePanel().setWidth('100%').setStyleAttributes({background: '#FBFBEF'})
  var form = complaintApp.createFormPanel();  
  var flow = complaintApp.createFlowPanel();
  var grid1 = complaintApp.createGrid(2, 1).setStyleAttributes({margin: "0 auto"});
  grid1.setWidget(0, 0, complaintApp.createHTML("<br/>"));
  grid1.setWidget(1, 0, complaintApp.createLabel("Please fill out the following, where applicable.")
                   .setStyleAttributes({textDecoration: "underline", fontSize: "16", fontWeight: "bold"}));
  var fuGrid = complaintApp.createGrid(1, 7).setStyleAttributes({margin: "0 auto"})//.setWidth('100%');
  var userName = complaintApp.createTextBox().setName('userName').setId('userName').setStyleAttributes({float: 'left'})
  fuGrid.setWidget(0, 0, complaintApp.createLabel("Your name:").setStyleAttributes({textAlign: 'right', fontWeight: "bold"}));
  fuGrid.setWidget(0, 1, userName);
  fuGrid.setWidget(0, 2, complaintApp.createLabel("Date/time of follow-up:").setStyleAttributes({textAlign: 'right', fontWeight: "bold"}));
  var fuDate = complaintApp.createDateBox().setFormat(UiApp.DateTimeFormat.DATE_SHORT).setName('fuDate').setId('fuDate').setStyleAttributes({float: 'left'})
  fuGrid.setWidget(0, 3, fuDate);
  var fuHour = complaintApp.createListBox().setName('fuHour').setId('fuHour').setWidth(60).setStyleAttributes({float: 'left'}).addItem("Hr");
  var fuMin = complaintApp.createListBox().setName('fuMin').setId('fuMin').setWidth(60).setStyleAttributes({float: 'left'}).addItem("Min");
for (h=0;h<24;++h){
  if(h<10){var hourstr='0'+h}else{var hourstr=h.toString()}
  fuHour.addItem(hourstr)
  }
  for (m=0;m<60;++m){
  if(m<10){var minstr='0'+m}else{var minstr=m.toString()}
  fuMin.addItem(minstr)
  }
  fuGrid.setWidget(0, 4, fuHour.setStyleAttributes({float: 'left'}));
  fuGrid.setWidget(0, 5, fuMin.setStyleAttributes({float: 'left'}));
  var fuDescGrid = complaintApp.createGrid(2, 4).setStyleAttributes({fontWeight: "bold", margin: "0 auto"}).setWidth('100%')
  fuDescGrid.setWidget(0, 1, complaintApp.createLabel('Description of Follow-up:'));
  var fuDesc = complaintApp.createTextArea().setName('fuDesc').setId('fuDesc').setWidth(500).setHeight(70).setStyleAttributes({overflow: "auto"})
  fuDescGrid.setWidget(1, 1, fuDesc);
  fuDescGrid.setWidget(1, 2, complaintApp.createLabel('Amount of appeasement:'));
  var fuApp = complaintApp.createTextArea().setName('fuApp').setId('fuApp');
  fuDescGrid.setWidget(1, 3, fuApp);
  var resSubClose = complaintApp.createGrid(1, 3).setStyleAttributes({margin: "0 auto"})
  var resHandler = complaintApp.createServerHandler("resolved");
  var resolved = complaintApp.createCheckBox("Issue is fully resolved.").setName("resCB").addValueChangeHandler(resHandler).setStyleAttributes({margin: "0 auto"});
  resSubClose.setWidget(0, 0, resolved)
  resSubClose.setWidget(0, 1, complaintApp.createSubmitButton("Submit"));
  var closeHandler = complaintApp.createServerHandler("close");
  var close = complaintApp.createButton("Close").addClickHandler(closeHandler);
  resSubClose.setWidget(0, 2, close)
  var resTf = complaintApp.createLabel("test").setId("resTf").setVisible(false)
  subPanel.add(grid1);
  flow.add(fuGrid);
  flow.add(fuDescGrid);
  flow.add(resSubClose);  
  form.add(flow);
  subPanel.add(form);
  complaintApp.add(subPanel);
  complaintApp.add(resTf);
  //var spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
  //spreadSheet.show(complaintApp);
  return complaintApp;
}
function resolved(e){
  var app = UiApp.getActiveApplication();
  if (e.parameter.resCB == true){
    app.getElementById('resTf').setText("Yes")
    return app;
  }
}
function close(e) {
  var app = UiApp.getActiveApplication();
  app.close();
  return app;
}

要发送电子邮件,您需要使用MailApp类:

MailApp类- Google文档

要从电子表格中获取数据,有一个电子表格应用程序类:

SpreadsheetApp类- Google Documentation

您可以使用getActive()方法获得对当前活动电子表格的引用:

getActive()方法

返回电子表格对象。一旦有了对当前电子表格的引用,就可以获得活动工作表,并从活动工作表获得一个二维值数组:

getSheetValues方法

这里有一个StackOverflow问题可能会对你有所帮助:

按列搜索电子表格

最新更新