[英]Google Apps Script problem using getLinkUrl(offset)
我試圖弄清楚如何在Google Apps腳本中使用getLinkUrl(offset)
。
我在這里找到了參考-http: //googlescriptreference.com/Document/Text/getlinkurloffset/ ,但是我找不到在線示例。
該GAS在日志中返回Paragraph
var paragraph = tableCell.getChild(0);
該GAS返回日志中the text string in the paragraph
中的the text string in the paragraph
var paragraphText = paragraph.getText();
該GAS在日志中返回NULL
var paragraphText = paragraph.getLinkUrl();
此GAS返回錯誤(找不到方法getLinkUrl(number)。),日志中沒有任何內容
var paragraphText = paragraph.getLinkUrl(2);
有人可以幫我了解如何使用getLinkUrl(offset)
嗎?
謝謝你的幫助!
我試圖直接在段落元素上使用getLinkUrl(offset)
(不起作用的示例),但是我需要在getLinkUrl(offset)
之前使用asText()
方法。
無法運作
var paragraphText = paragraph.getLinkUrl(2);
工作
var paragraphText = paragraph.asText().getLinkUrl(2);
Google文件 https://docs.google.com/document/d/136G549zIYPYBndXs70ZnR_wEFg5fPST9ZGsOlTgmDyM/edit
//Works if link is on a word or words instead of entire paragraph
function myFunctionP1() {
//Find out how many Children there are
var body = DocumentApp.getActiveDocument().getBody();
Logger.log(body.getNumChildren());
//Find out which child is table
var table = body.getChild(2); //table is child#2
Logger.log(table);
//Find tableCell inside of table
var tableCell = table.getChild(0).getChild(0); //tableCell
Logger.log(tableCell)
//Find paragraph inside of tableCell
//I think, but I'm not sure, the HYPERLINK will be found somewhere within the PARAGRAPH element. But I can't figure out how to get to it.
var paragraph = tableCell.getChild(0); //paragraph element
Logger.log(paragraph)
//Get paragraph text
var paragraphText = paragraph.asText().getLinkUrl(2); //paragraph text
Logger.log(paragraphText)
}
//Works if link is on entire paragraph
//Works if link is on entire paragraph
//Works if link is on entire paragraph
function myFunctionP2() {
//Find out how many Children there are
var body = DocumentApp.getActiveDocument().getBody();
Logger.log(body.getNumChildren());
//Find out which child is table
var table = body.getChild(4); //table is child#2
Logger.log(table);
//Find tableCell inside of table
var tableCell = table.getChild(0).getChild(0); //tableCell
Logger.log(tableCell)
//Find paragraph inside of tableCell
//I think, but I'm not sure, the HYPERLINK will be found somewhere within the PARAGRAPH element. But I can't figure out how to get to it.
var paragraph = tableCell.getChild(0); //paragraph element
Logger.log(paragraph)
//Get paragraph text
var paragraphText = paragraph.getText(); //paragraph text
Logger.log(paragraphText)
//Get HYPERLIINK from paragraph text
var paragraphHYPERLINK = paragraph.getLinkUrl(); //paragraph text
Logger.log(paragraphHYPERLINK)
}
@Tanaike幫助我找到了這個解決方案。 https://stackoverflow.com/users/7108653/tanaike
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.