Google脚本用户界面 - 从电子表格中读取和发布,链接到已填充的用户界面

时间:2014-07-14 21:12:47

标签: google-apps-script google-apps

我创建了一个用户界面,我想用来读取和发布到spreadsheet。现在,请忽略col A中的链接格式。现在,它将链接到表单。我想改用UI,并在设置完成后立即删除对链接表单的引用。

Here is the current UI

我希望最终结果是: 1.提交新条目后,经理会通过电子邮件发送链接。

  1. 该链接将打开用户界面。

  2. 顶部(灰色)区域将使用电子表格中的相关值填充,具体取决于ID号(A列)。

  3. 底部区域将为空白,或填充相应的电子表格中的值(如果存在)。

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

  5. 输入到用户界面的数据会在正确的列中填充电子表格。

  6. 查看电子表格的用户将能够点击ID号码,它将启动已填充的用户界面。

  7. 使用Forms非常简单,但我正在寻找更灵活的东西,所以我使用的是UI。

    以下是我的问题: 1.我找不到一个可以搜索值的简单,直接的脚本,并且一旦找到该值,就会获得包含该值的行中的其余数据。      ◦我为此疯狂搜索,每个人似乎都有不同的想法,但没有一个符合我的要求。

    1. 我了解如何将值从用户界面传递到电子表格,但反之亦然。

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

    3. 用户界面的代码如下。是的,我知道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;
      }
      

1 个答案:

答案 0 :(得分:0)

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

MailApp Class - Google Documentation

要从电子表格中获取数据,有一个SpreadsheetApp类:

SpreadsheetApp Class - Google Documentation

您可以使用getActive()方法获取对当前有效电子表格的引用:

getActive() Spreadsheet Method

返回电子表格对象。获得当前电子表格的引用后,您可以获取活动工作表,并从活动工作表中获取二维数组值:

getSheetValues Method

这是一个可能对您有帮助的StackOverflow问题:

Search a Spreadsheet by column