如何使用Google App脚本获取链接到工作表的表单? [英] How to get a form linked to a sheet using google app script?

查看:88
本文介绍了如何使用Google App脚本获取链接到工作表的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在类电子表格中,有getFormUrl()返回网址对于附加到电子表格的表单,如果没有表单,则为null.

In class Spreadsheet there is getFormUrl() which returns the url for the form attached to the spreadsheet, null if there is no form.

但是现在您可以在每个工作表上附加一个表单,那么如何获取给定工作表上附加的表单的ID或网址?

But now that you can have a form attached to each sheet, how do you get the ID or Url of the form attached to a given sheet?

推荐答案

我注意到,sheet.getFormURL()方法并不总是返回与form.getPublishedUrl()返回的URL相同的URL.这两个URL均有效.为了解决该问题,我打开工作表的formUrl,然后检查并比较该表单的ID:

I've noticed that the sheet.getFormURL() method does not always return the same URL that form.getPublishedUrl() returns. Both URLs are valid, though. To get around the problem, I'm opening the sheet's formUrl and then checking and comparing that form's ID:

var form = FormApp.getActiveForm();
var formId = form.getId();
const matches = spreadSheet.getSheets().filter(function (sheet) {
  var sheetFormUrl = sheet.getFormUrl();
  if (sheetFormUrl){
    return FormApp.openByUrl(sheetFormUrl).getId() === formId;
  }
});
const sheet = matches[0]

这篇关于如何使用Google App脚本获取链接到工作表的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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