【发布时间】:2020-05-28 22:17:35
【问题描述】:
我的目标是创建一个电子表格单元格,其中包含来自 Google 脚本的多个超链接。
我可以创建一个包含多个链接的单元格,选择部分单元格文本,然后使用 Ctrl + K 或菜单 insert link。我的单元格以google and yahoo 为例,有两个超链接,每个搜索引擎一个。
我可以通过两种不同的方式阅读此单元格中的超链接:
var range = SpreadsheetApp.getActiveSheet().getRange('A1');
var richText = range.getRichTextValue();
var allRuns = richText.getRuns();
var firstLink = allRuns[0].getLinkUrl();
var secondLink = allRuns[2].getLinkUrl();
var gLink = richText.getLinkUrl(0, 5);
var aLink = richText.getLinkUrl(11, 15);
但是没有可用的setLinkUrl 方法。我在Google sheets API 中也找不到任何东西。
我复制了这个单元格并在 Linux 中使用 xclip 命令
xclip -selection clipboard -o -t text/html
结果是
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
td {
border: 1px solid #ccc;
}
br {
mso-data-placement: same-cell;
}
-->
</style>
<span style="font-size: 10pt; font-family: Arial; font-style: normal;"
data-sheets-value="{"1":2,"2":"google and yahoo"}"
data-sheets-userformat="{"2":1049089,"3":{"1":0},"12":0,"23":1}"
data-sheets-textstyleruns="{"1":0,"2":{"2":{"1":2,"2":1136076},"9":1}}{"1":6}{"1":11,"2":{"2":{"1":2,"2":1136076},"9":1}}"
data-sheets-hyperlinkruns="{"1":0,"2":"https://www.google.com/"}{"1":6}{"1":11,"2":"https://www.yahoo.com/"}{"1":16}"><span
style="font-size: 10pt; font-family: Arial; font-style: normal; text-decoration: underline; -webkit-text-decoration-skip: none; text-decoration-skip-ink: none; color: #1155cc;"><a
class="in-cell-link" target="_blank" href="https://www.google.com/">google</a></span><span
style="font-size: 10pt; font-family: Arial; font-style: normal;">
and </span><span
style="font-size: 10pt; font-family: Arial; font-style: normal; text-decoration: underline; -webkit-text-decoration-skip: none; text-decoration-skip-ink: none; color: #1155cc;"><a
class="in-cell-link" target="_blank" href="https://www.yahoo.com/">yahoo</a></span></span>
我不确定这是否意味着超链接有自己的运行,独立的表单文本样式运行?任何指针表示赞赏。
【问题讨论】:
标签: google-apps-script google-sheets hyperlink google-sheets-api