Google 使用 getLinkUrl(offset) 的 Apps 脚本问题
Google Apps Script problem using getLinkUrl(offset)
我正在尝试了解如何在 Google Apps 脚本中使用 getLinkUrl(offset)
。
我在此处找到了参考资料 - http://googlescriptreference.com/Document/Text/getlinkurloffset/,但我在网上找不到任何示例。
这个 GAS returns Paragraph
在日志中
var paragraph = tableCell.getChild(0);
这个 GAS returns the text string in the paragraph
在日志中
var paragraphText = paragraph.getText();
这个 GAS returns NULL
在日志中
var paragraphText = paragraph.getLinkUrl();
这个 GAS returns 一个错误(找不到方法 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://whosebug.com/users/7108653/tanaike
我正在尝试了解如何在 Google Apps 脚本中使用 getLinkUrl(offset)
。
我在此处找到了参考资料 - http://googlescriptreference.com/Document/Text/getlinkurloffset/,但我在网上找不到任何示例。
这个 GAS returns Paragraph
在日志中
var paragraph = tableCell.getChild(0);
这个 GAS returns the text string in the paragraph
在日志中
var paragraphText = paragraph.getText();
这个 GAS returns NULL
在日志中
var paragraphText = paragraph.getLinkUrl();
这个 GAS returns 一个错误(找不到方法 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://whosebug.com/users/7108653/tanaike