2017-10-10 127 views
0

我不知道如何找到偏移值使用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) 

注:我沒有使用此文件的約束容器。

+0

謝謝,也請你提一下如何找到抵消位置 – user2326333

回答

1

您想要將文本附加到段落並使該文本成爲超鏈接。這是如何。

doc.appendParagraph('Tracking bug: ').appendText("567587").setLinkUrl("http://example.com"); 

該方法工作鏈:appendParagraph返回一個新創建的段落; appendText返回新添加的文本元素; setLinkUrl鏈接文本元素。無需補償。