如何使用PHP中的API获取与谷歌表链接的谷歌表格。 或与谷歌表格链接的表格

How to get google form linked with google sheet using api in php. or Google sheet linked to form.

I have list of Google form using API and I want to get the Google sheet used to save responses of form. Or I have also list of google sheets is there way I can get form id linked with google sheet.

Run this in any spreadsheet and it will list each of the sheets and, if a sheet is linked to a form, it will list the url, ID and Title of the linked form.


  function LoopSheets4Forms(){
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheets = ss.getSheets();
      var numSheets = sheets.length
      if (numSheets > 1) {
        for (i=0;i<numSheets;i++){
          var sheetname = sheets[i].getName();
          Logger.log("DEBUG:i="+i+", Sheet name: "+ sheetname);//DEBUG
          var formURL =  sheets[i].getFormUrl();
          if(formURL != null){
            // not null
            Logger.log("DEBUG:Form url:"+formURL);//DEBUG
            var form = FormApp.openByUrl(formURL);
            Logger.log("DEBUG:Form title: "+form.getTitle());//DEBUG
            var formId = form.getId();
            Logger.log("DEBUG:Form id: "+ formId );//DEBUG
          }
          else
          {
            // is null
            Logger.log("DEBUG: this sheet not linked to a form");//DEBUG
          }
        }
      }
    }