Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 绑定的Google脚本能触发Google Web应用程序吗?_Google Apps Script_Google Sheets_Web Applications - Fatal编程技术网

Google apps script 绑定的Google脚本能触发Google Web应用程序吗?

Google apps script 绑定的Google脚本能触发Google Web应用程序吗?,google-apps-script,google-sheets,web-applications,Google Apps Script,Google Sheets,Web Applications,我有一个运行良好的Web应用程序,可以创建一个Google文档。该应用程序安装在谷歌新网站的一个按钮中。有时,我需要从站点创建一个新文档,但有时我需要在打开Google电子表格时创建一个新文档(该表格包含与站点相关的数据,并嵌入到站点中) 我在那张纸上有一个定制菜单,可以做很多不同的事情。我想在菜单中添加一个项目,用于访问上述Web应用程序并运行它 首先,这可能吗 其次,我假设如果可能的话,那么不知何故,我必须使用它的URL调用Web应用程序脚本(就像我在我的Google站点上附加的按钮一样)

我有一个运行良好的Web应用程序,可以创建一个Google文档。该应用程序安装在谷歌新网站的一个按钮中。有时,我需要从站点创建一个新文档,但有时我需要在打开Google电子表格时创建一个新文档(该表格包含与站点相关的数据,并嵌入到站点中)

我在那张纸上有一个定制菜单,可以做很多不同的事情。我想在菜单中添加一个项目,用于访问上述Web应用程序并运行它

首先,这可能吗

其次,我假设如果可能的话,那么不知何故,我必须使用它的URL调用Web应用程序脚本(就像我在我的Google站点上附加的按钮一样)

我的Web应用程序代码如下:

代码.gs Index.html

填写以下字段以命名谷歌歌词文档
并添加歌曲标题和作者。
然后单击按钮创建新歌歌词文档。







创建新的歌词文档 window.saveUserInput=函数(){ var docName=document.getElementById('idNewDocName')。值; var songTitle=document.getElementById('idNewSongTitle')。值; var songWriters=document.getElementById('idNewSongWriters').value; console.log('songTitle:'+songTitle) google.script.run .withSuccessHandler(openNewDoc) .createNewLandscapeSong({docName:docName,songTitle:songTitle,词曲作者:词曲作者}) } 函数openNewDoc(结果){ window.open(results.url,“_blank”).focus(); }
绑定脚本:SP目录菜单
/*此菜单正在使用中。
此函数用于创建自定义菜单。注意:第3行抛出错误,但是这个脚本可以工作*/
函数onOpen(){
//SpreadsheetApp.getActiveSpreadsheet().toast('任务已启动');
var ui=SpreadsheetApp.getUi();
ui.createMenu('SP')
.addItem('网站','开放网站')
.addItem('打开谷歌硬盘','打开硬盘')
.addItem('打开旧SP站点','打开旧SP')
.addItem('Create','openCreate')
.addItem('Perform','openPerform')
.addItem('Catalog','openCatalog')
.addItem('New Lyric-Landscape'、'createLandscapeLyricDoc')
.addItem('newlyrict-Landscape Test','newLyricTest')
.addItem('新歌词-肖像','开放肖像')
.addItem('将歌曲添加到目录','添加歌曲')
.addToUi();
}
函数openSite(){
var selection=SpreadsheetApp.getActiveSheet();
var html=“”;
var userInterface=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModalDialog(用户界面,'Open SP');
}
函数openDrive(){
var selection=SpreadsheetApp.getActiveSheet();
var html=“”;
var userInterface=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModalDialog(用户界面,“打开我的谷歌硬盘”);
}
函数openOldSP(){
var selection=SpreadsheetApp.getActiveSheet();
var html=“”;
var userInterface=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModalDialog(用户界面,“打开我的谷歌硬盘”);
}
函数openCreate(){
var selection=SpreadsheetApp.getActiveSheet();
var html=“”;
var userInterface=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModalDialog(用户界面,“打开创建工作表”);
}
函数openPerform(){
var selection=SpreadsheetApp.getActiveSheet();
var html=“”;
var userInterface=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModalDialog(用户界面,“打开执行表”);
}
函数createLandscapeLyricDoc(){
var doc=DocumentApp.create('Rename');
var title=“替换为歌曲标题,然后将此文本链接到目录电子表格中的歌曲标题单元格”
var url=doc.getUrl();
var body=doc.getBody();
var段落=正文。插入段落(0“”);
var text1=段落.appendText(©替换为编写器);
text1.setFontSize(8);
var rowsData=[[“在这里放第一首诗/合唱(建议使用所有大写)。”,“在这里放第二首诗/下一首合唱/桥牌/等等”。]];
var style={};
正文.插入段落(0,标题)
.设置标题(文件第页段落标题3);
table=body.appendTable(rowsData);
样式[DocumentApp.Attribute.BORDER\u WIDTH]=0;
表1.setAttributes(样式);
var html=';'
var selection=SpreadsheetApp.getActiveSheet();
var userInterface=HtmlService.createHtmlOutput(html);
/*注意:调试时,以下行会引发错误,
但是脚本可以从目录表SP菜单中工作*/
SpreadsheetApp.getUi().showmodaldialdialog(用户界面,'Open-Landscape-New-Lyric-Doc');
}
函数newLyricTest(){
//这就是我想调用运行SPSiteNewSongButtonScript(Web应用程序)的地方
}
函数opengrait(){
var html=“”;
var selection=SpreadsheetApp.getActiveSheet();
var userInterface=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showmodaldialdialog(用户界面,“打开肖像新歌词文档”);
}  
函数addSong(){
var ss=SpreadsheetApp.getActive();
var sheet=ss.getActiveSheet();
var lastRow=sheet.getLastRow()
第页附录行([lastRow+1]);
SpreadsheetApp.flush();
var range=sheet.getRange(sheet.getLastRow(),1);
var songtTitle=Browser.inputBox('New Song','Enter the Song title',Browser.Buttons.OK\u CANCEL);
var namedRange=sheet.getRange(“标题”);
var range=sheet.getRange(sheet.getLastRow(),namedRange.getColumn())
range.setValue(歌曲标题);
SpreadsheetApp.setActiveRange(范围);
}

实现这一点的方法很少,
1) 使用或在google电子表格中呈现HTML页面。它的行为就像电子表格中的一个webapp

伪代码: 首先在电子表格(html和code.gs)中复制您的webapp,然后修改您的
newLyricTest()

当您运行上述代码时,html页面的值将呈现在页面的一侧
function doGet() {
  return HtmlService
      .createTemplateFromFile('Index')
      .evaluate();
}

function createNewLandscapeSong(objArgs) {
  var docName = objArgs.docName;
  var songTitle = objArgs.songTitle;
  var songWriters = objArgs.songWriters;

  Logger.log('songTitle: ' + songTitle)

  var doc = DocumentApp.create(docName);

  var url = doc.getUrl();
  var body = doc.getBody();
  var paragraph = body.insertParagraph(0, "");
  var text = paragraph.appendText("© "+songWriters);
  text.setFontSize(8);
  var rowsData = [['PUT FIRST VERSE/CHORUS HERE.', 'PUT SECOND VERSE/NEXT CHORUS/BRIDGE/ETC HERE.']];
  var style = {};
  body.insertParagraph(0, songTitle)
  .setHeading(DocumentApp.ParagraphHeading.HEADING3);
  table = body.appendTable(rowsData);
  style[DocumentApp.Attribute.BORDER_WIDTH] = 0;
  table.setAttributes(style);

  return {
   url: url,
   songTitle: songTitle
  };
}
/*This menu in use.

This function creates the custom menu. Note: Line 3 throws error, but this script works.*/
function onOpen() {
  //SpreadsheetApp.getActiveSpreadsheet().toast('Task started');
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('SP')
      .addItem('Website', 'openSite')
      .addItem('Open Google Drive', 'openDrive')
      .addItem('Open Old SP Site', 'openOldSP')
      .addItem('Create', 'openCreate')
      .addItem('Perform', 'openPerform')
      .addItem('Catalog', 'openCatalog')
      .addItem('New Lyric - Landscape', 'createLandscapeLyricDoc')
      .addItem('New Lyric - Landscape Test', 'newLyricTest')
      .addItem('New Lyric - Portrait', 'openPortrait')
      .addItem('Add Song to Catalog', 'addSong')
      .addToUi();
}
function openSite() {
  var selection = SpreadsheetApp.getActiveSheet();
  var html = "<a href='https://sites.google.com/view/sp-site/catalog'; target='_blank'>Open SP</a>";
  var userInterface = HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open SP');
  }
function openDrive() {
  var selection = SpreadsheetApp.getActiveSheet();
  var html = "<a href='https://drive.google.com/drive/my-drive'; target='_blank'>Open My Google Drive</a>";
  var userInterface = HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open My Google Drive');
  }
function openOldSP() {
  var selection = SpreadsheetApp.getActiveSheet();
  var html = "<a href=url'; target='_blank'>Open Old SP Site</a>";
  var userInterface = HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open My Google Drive');
  }
function openCreate() {
  var selection = SpreadsheetApp.getActiveSheet();
  var html = "<a href='url'; target='_blank'>Open Create Spreadsheet</a>";
  var userInterface = HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open Create Sheet');
}
function openPerform() {
  var selection = SpreadsheetApp.getActiveSheet();
  var html = "<a href= 'url'; target='_blank'>Open Perform Spreadsheet</a>";
  var userInterface = HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open Perform Sheet');
}
function createLandscapeLyricDoc() {
  var doc = DocumentApp.create('Rename');
  var title = "replace with song title and then link this text to song title cell in Catalog Spreadsheet"
  var url = doc.getUrl();
  var body = doc.getBody();
  var paragraph = body.insertParagraph(0, "");
  var text1 = paragraph.appendText("© replace with writer(s)");
      text1.setFontSize(8);
  var rowsData = [['PUT FIRST VERSE/CHORUS HERE.  (SUGGEST USE ALL CAPS.)', 'PUT SECOND VERSE/NEXT CHORUS/BRIDGE/ETC HERE.']];
   var style = {};
  body.insertParagraph(0, title)
      .setHeading(DocumentApp.ParagraphHeading.HEADING3);
  table = body.appendTable(rowsData);
  style[DocumentApp.Attribute.BORDER_WIDTH] = 0;
  table.setAttributes(style);
  var html = '<a href= "' + url + '"; target="_blank">Open new lyric doc</a>;'
  var selection = SpreadsheetApp.getActiveSheet();
  var userInterface = HtmlService.createHtmlOutput(html);
  /*Note: The following line throws error when you debug, 
  but the script works from the Catalog Sheet SP Menu.*/
  SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open Landscape New Lyric Doc');
}
function newLyricTest() {
// This is where I want to put call to run the SPSiteNewSongButtonScript (Web App)
}
function openPortrait() {
  var html = "<a href= 'url'; target='_blank'>Open 1-Column Lyric Template</a>";
  var selection = SpreadsheetApp.getActiveSheet();
  var userInterface = HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open Portrait New Lyric Doc');
}  
function addSong() {
    var ss = SpreadsheetApp.getActive();
    var sheet = ss.getActiveSheet();
    var lastRow = sheet.getLastRow()
    sheet.appendRow([lastRow+1]);
    SpreadsheetApp.flush();
    var range = sheet.getRange(sheet.getLastRow(), 1);
    var songTitle = Browser.inputBox('New Song', 'Enter the song title', Browser.Buttons.OK_CANCEL);
    var namedRange = sheet.getRange("Title");
    var range=sheet.getRange(sheet.getLastRow(), namedRange.getColumn())
  range.setValue(songTitle);
    SpreadsheetApp.setActiveRange(range);
}
function newLyricTest() 
{
  var html = HtmlService.createHtmlOutputFromFile('Index')
      .setTitle('My custom sidebar')
      .setWidth(300);
  SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
      .showSidebar(html);
}
function newLyricTest() 
    {
   var ui = SpreadsheetApp.getUi();  
   var result = ui.prompt(
      'New Lyric Test',
      'Please enter Document name:',
      ui.ButtonSet.OK_CANCEL);

  // Process the user's response.
  var button = result.getSelectedButton();
  var text = result.getResponseText();
  if (button == ui.Button.OK) {
    // User clicked "OK".
    var docName = text
  } else if (button == ui.Button.CANCEL) {
    // User clicked "Cancel".
    return // exit function
  } else if (button == ui.Button.CLOSE) {
    // User clicked X in the title bar.
    return // exit function
  }

   // Now repeat the process as above to get values for songTitle and songWriters.
  // once you have the values of all these variables you can run the remaining code
  // of function createNewLandscapeSong()
  Logger.log('songTitle: ' + songTitle)

  var doc = DocumentApp.create(docName);

  var url = doc.getUrl();
  var body = doc.getBody();
  var paragraph = body.insertParagraph(0, "");
  var text = paragraph.appendText("© "+songWriters);
  text.setFontSize(8);
  var rowsData = [['PUT FIRST VERSE/CHORUS HERE.', 'PUT SECOND VERSE/NEXT CHORUS/BRIDGE/ETC HERE.']];
  var style = {};
  body.insertParagraph(0, songTitle)
  .setHeading(DocumentApp.ParagraphHeading.HEADING3);
  table = body.appendTable(rowsData);
  style[DocumentApp.Attribute.BORDER_WIDTH] = 0;
  table.setAttributes(style);

  return {
   url: url,
   songTitle: songTitle
  };
}