使用谷歌脚本如何找到抵消插入文本
问题描述:
我不知道如何找到偏移值使用insertText方法使用谷歌脚本如何找到抵消插入文本
我的谷歌文档应该看一些东西一样
第1款
款2
跟踪错误:567587
第3段
所有段落数据都从excel中提取并写入文档
使用附加段落我无法仅为'567587'使用url。下面的脚本是迄今为止我创建
var doc=DocumentApp.openById('abcxxdcdcd').getBody();
var text=doc.editAsText();
doc.appendParagraph('paragraph1');
doc.appendParagraph('paragraph2');
doc.appendParagraph('Tracking bug: ');
//I want to insert text next to the above paragraph 'Tracking bug: ' which means I need to find the offset of the location.
text.insertText(offset,567587).setLinkUrl(startOffset, endOffsetInclusive, url)
注:我没有使用此文件的约束容器。
答
您想要将文本附加到段落并使该文本成为超链接。这是如何。
doc.appendParagraph('Tracking bug: ').appendText("567587").setLinkUrl("http://example.com");
该方法工作链:appendParagraph
返回一个新创建的段落; appendText
返回新添加的文本元素; setLinkUrl
链接文本元素。无需补偿。
谢谢,也请你提一下如何找到抵消位置 – user2326333