google-apps-script - 在 Google 脚本中,如何将 doc url 变量传递到 href 语句中?
问题描述
我在 Google 表格中有一个绑定的 Google 脚本,它创建一个菜单并使用一堆函数填充工作表的 onOpen 菜单。一个函数创建一个新的 Google Doc。然后我想打开那个文档,但我不知道如何将文档的 URL 传递到 href 语句中。请参见下面的代码:
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);
/*line below is the one that does not work as the variable "url" is not being read correctly (as I don't know how to use it or if this can even be done)*/
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 Landscape New Lyric Doc');
有人建议这个问题已经在这里得到了回答,虽然我可以理解为什么提出这个建议,但我有以下观察结果:
1)我对谷歌脚本编码太陌生了,不知道足够多的术语来在 Stack Overflow 上形成搜索查询来找到答案。事实上,如果我以某种方式偶然发现了那个“答案”,我不确定我是否会认出它,因为整体代码与我正在努力解决的代码是如此不同。
2) 在我提出问题之前,该解决方案并未作为建议的解决方案之一出现。
综合考虑这两点,尤其是对于新手编码人员,我认为在这个网站上提出我的问题将对符合我个人资料(而不是经验丰富的编码人员)的其他人有所帮助,因为这个问题和答案可能会出现在其他人试图做我曾经/正在尝试做的事情,而如何在字符串问答中使用变量则不会。
解决方案
桑迪·古德回答:
var html = '<a href= "' + url + '"; target="_blank">Open 1-Column Lyric Template</a>;'
推荐阅读
- python - 使用 nargs 参数时,如何使 argparse.ArgumentParser 返回元组或 np.array 而不是列表?
- javascript - 单击带有 window.onbeforeunload 的链接时出现问题
- kml - 使用区域、网络链接、kml 中的时间跨度,但 GE 在启动时加载整个文件
- python-3.x - 带有数据框的 UDF
- html - 试图将宽度继承到css中的img标签
- android - Gradle - 创建 android apk 后立即运行 CustomTask
- java - /test/resources 中存在的访问文件 - 类路径问题
- azure - 通过 Azure VPN 网关从外部计算机连接到本地网络
- node.js - 如何避免重复使用 Node.js 推送到 Kafka 主题的消息?
- jquery - $('script#id').html() 从车把模板返回“”数据[仅限 firefox]