Google Apps脚本-绘制为按钮以打开Goog​​le表单 [英] Google apps script - drawing as button to open Google form

查看:61
本文介绍了Google Apps脚本-绘制为按钮以打开Goog​​le表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我与一家非常小的公司合作,并且正在使用Google表格中的共享联系人数据库.我想包括的一件事是一个简单的按钮(我刚刚使用了我在图纸中制作的图形),上面写着添加新联系人",单击该按钮会打开我创建的Google表单,该表单将收集联系人信息并存储在其中的Google表格.

So I work with a very small business and I am working on shared contact database in Google Sheets. One of the things I would like to include is a simple button (I just used a drawing I made in Sheets) that says "Add New Contact" and when clicked it opens up a Google Form I created that will collect the contact info and store in it the Google Sheet.

我的问题是...我可以使用什么Google应用程序脚本来完成该任务?我是Google Apps脚本的新手,所以我真的不知道如何正确编写代码.

My question is... What Google app script can I use to achieve that task? I'm very new to Google Apps script so I don't really know how to go about writing the code properly.

感谢您的回答!

推荐答案

我只想要一个简单的按钮!

创建按钮的最简单方法是在脚本编辑器中创建一个新的html文件.完成后,它将打开一个文件并询问名称.您添加名称"AddNewContent"并在文件中查找,它将具有此内容.

I just want a Simple Button!

The easiest way to create a button is to create a new html file in the script editor. When you do, it will open up a file and ask for a name. You add the name "AddNewContent" and look in the file and it will have this content.

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>

  </body>
</html>

添加内容,使其看起来像这样:

Add content so that it looks like this:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
      function addNewContent()
      {
        google.script.run.addNewContent();
      }
    </script>
  </head>
  <body>
    <input id="btn0" type="button" value="Add New Contact" onClick="addNewContact();" />
  </body>
</html>

现在转到Code.gs文件.当您开始一个新项目时,Code.gs文件将自动添加,并且包含以下内容:

Now go to the Code.gs file. When you start a new project the Code.gs file is added automatically and it contains the following:

function myFunction(){

}

用以下代码替换代码:

function addNewContent()
{

}

现在,您有一个连接到Google Apps脚本功能外壳的按钮.要在边栏上显示按钮,您可以在Code.gs文件中创建另一个函数,如下所示:

Now you have a button that's connected to the shell of a Google Apps Script Function. To display the button on a sidebar you can create another function in the Code.gs file like the one below:

function showSideBar()
{
  var userInterface=HtmlService.createHtmlOutputFromFile('AddNewContent');
  SpreadsheetApp.getUi().showSidebar(userInterface);
}

然后要轻松显示侧边栏,可以将showSideBar函数添加到菜单上,该菜单将在您每次打开电子表格时创建.

And then to display the sidebar easily you can add the showSideBar function to a menu which will be created whenever you open your spreadsheet.

function onOpen()
{
  SpreadsheetApp.getUi().createMenu('My New Menu').addItem('Display my Sidebar', 'showSideBar').addToUi();

}

因此,如果您保存了所有这些文件并在代码编辑器中选择了onOpen函数,则菜单如下图所示,然后按三角按钮,它将运行onOpen函数,而您不必关闭并重新打开程序使其运行,菜单将神奇地显示在电子表格上.现在,您可以显示侧边栏并运行Google Apps脚本功能.

So if you save all of those files and select the onOpen function in the code editor so that the menu looks like the image below and press the triangular button then it will run the onOpen function and you won't have to close and reopen the program to get it to run and the menu will magically appear on the spreadsheet. Now you can display your side bar and run your Google Apps Script function.

不幸的是,该功能还没有执行任何操作,因为我实际上并不知道您想做什么或感到沮丧.如果您已经创建了Google表单,那么它已经将自己链接到电子表格,并且已经在收集数据.如果您创建了自己的HTML表单(这很可疑),则可以将其显示为对话框或将其部署为Web应用程序.

Unfortunately, the function doesn't do anything yet because I don't actually know what you want to do or have down. If you already created a Google Form then it has already linked itself to a spreadsheet and it's already collecting data. If you have created an HTML form of your own (which is doubtful) then you can display it as a dialog or deploy it as a web app.

因此,真正的问题是您做了什么以及您想从这里去哪里.不幸的是,编写Google Apps脚本需要对Javascript,HTML,一些CSS以及我对JQuery的一点了解.它还涉及大量的阅读和研究.虽然您现在可能不相信.在文档中可以找到关于Google Apps脚本的大多数问题. .我建议您去那里阅读,然后一次又一次地重新阅读,直到您知道在哪里可以找到编写脚本所需的一切.在大多数情况下,当我需要某些东西时,可以在Google搜索中找到它,并且经常使我回到该站点.但是,许多问题的答案涉及我很多方面的学习.

So the real question is what have you done and where do you want to go from here. Unfortunately, writing Google Apps Script requires a fair knowledge of Javascript, HTML, a little CSS and in my case a bit of JQuery. It also involves a far amount of reading and research. And while you may not believe it now. Most of the questions I had about Google Apps Script are found in the documentation. Which is where I'd recommend that you go and read and then reread again and again until you know where to find everything you need to write your scripts. Most of the time when I need something I can find it in a Google Search and very often it will bring me right back to this site. But many of the answers to questions involve a fair amount of learning on my part.

我第一次尝试学习Google Apps脚本是在2009年,由于我迷路了寻找文档的工作,所以我最终放弃了.但是大约10个月前,我再次看了一下,真的很喜欢我在文档的组织方式方面所看到的内容,因此我又跳了进去.几个月后,我开始访问StackOverFlow.com,然后我在这里和那里回答了一些问题,现在大约8个月后,我对许多与电子表格相关的任务感觉很好.我在几个方面仍然很虚弱,徘徊在这个站点上使我想起了我可能学到的所有东西.

The first time I tried to learn Google Apps Script was in 2009 and I finally gave up because I just got lost looking for documentation. But about 10 months ago I took another look and really liked what I saw in terms of how the documentation was organized so I jumped in again. A couple of months later I started visiting StackOverFlow.com and then I answered a few questions here and there and now about 8 months later I feel pretty good about many spreadsheet related tasks. I'm still weak in several areas and hanging around this site helps to remind me of all the things I could be learning.

这篇关于Google Apps脚本-绘制为按钮以打开Goog​​le表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆