如何使用Google Doc API脚本在Google文档中的表(或数组)中添加超链接?
我有以下代码在Google文档中附加表。
var sss = SpreadsheetApp.openById('id of spreadsheet');
var rawData = sss.getDataRange().getValues()
var data = []
for (var i = 0; i< rawData.length; i++){
tempData=[]
tempData=[rawData[i][1],rawData[i][2],rawData[i][3]]
data.push(tempData)
}
var someDoc = DocumentApp.openById(someId);
var body = someDoc.getBody();
body.appendTable(data).editAsText().setBold(false);
此代码正常。问题是rawdata [i] [3]
中有URL。它在Google文档中显示为纯文本。如何将其转换为超链接?如果可以将其写入body.appendParagraph(“我的链接”).setlinkurl(“ http://www.google.com”)
,那就更好了。问题在于它在数组中,而不是在段落中。
I am having the following code for appending table in Google Docs.
var sss = SpreadsheetApp.openById('id of spreadsheet');
var rawData = sss.getDataRange().getValues()
var data = []
for (var i = 0; i< rawData.length; i++){
tempData=[]
tempData=[rawData[i][1],rawData[i][2],rawData[i][3]]
data.push(tempData)
}
var someDoc = DocumentApp.openById(someId);
var body = someDoc.getBody();
body.appendTable(data).editAsText().setBold(false);
This code works fine. The problem is that there is url in rawdata[i][3]
. It gets displayed in Google doc as plain text. How can I convert it into hyperlink? It would be even better if it is possible to write it as body.appendParagraph("my link").setLinkUrl("http://www.google.com")
. The problem is that it is in an array, not in paragraph.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您的目标如下。
在这种情况下,以下修改如何?
修改后的脚本:
注意:
此修改后的脚本认为您的“ D”列值就像
https:// ###
和http:// ####
。请小心。如果要使用超链接使用特定文本(例如,
单击此处
),请按以下方式修改。来自
to
文献:
I believe your goal is as follows.
In this case, how about the following modification?
Modified script:
Note:
This modified script supposes that your values of column "D" are like
https://###
andhttp://###
. Please be careful about this.If you want to give the specific text (for example,
click here
) with the hyperlink, please modify as follows.From
To
References:
您可以尝试以下内容,以在Google Doc可单击中制作所有URL:
You can try the following to make all URLs in a Google Doc clickable: