问题描述
我正在尝试删除幻灯片的所有超链接.
I am trying to remove all hyperlinks of the slide.
下面是我尝试过的代码,但是没有用.你能告诉我我哪里出问题了吗?
Below is the code I have tried but that doesnt work. Can you tell me where I have gone wrong?
function run()
{
var ppt = SlidesApp.getActivePresentation();
var slide = ppt.getSlides()[0];
var pe = slide.getPageElements();
var startOffset = pe[0].asShape().getText().getLinks()[0].getStartIndex();
var endOffset = pe[0].asShape().getText().getLinks()[0].getEndIndex();
pe[0].asShape().getText().getRange(startOffset, endOffset).getTextStyle().setLinkUrl(null)
}
推荐答案
我相信您的目标如下.
- Q1.您想知道脚本问题的原因.
- 第二季度.您要使用Google Apps脚本删除Google幻灯片中幻灯片中的所有超链接.
为此,这个答案如何?
在脚本中,setLinkUrl(null)
用于删除链接.这就是您遇到问题的原因.在这种情况下,请使用removeLink()
而不是setLinkUrl(null)
. 参考
In your script, setLinkUrl(null)
is used for deleting the link. This is the reason of your issue. In this case, please use removeLink()
instead of setLinkUrl(null)
. Ref
在脚本中,尝试删除第一页上第一形状的文本的第一超链接.这就是您遇到问题的原因.为了删除Google幻灯片中幻灯片中的所有超链接,下面的示例脚本如何?
In your script, you try to delete the 1st hyperlink of the text in the 1st shape on the 1st page. This is the reason of your issue. In order to delete all hyperlinks in a slide in a Google Slides, how about the following sample script?
function myFunction() {
const slides = SlidesApp.openById("###").getSlides(); // Please set the Slides ID.
const otherTypes = {"IMAGE": "asImage", "LINE": "asLine", "SHEETS_CHART": "asSheetsChart", "WORD_ART": "asWordArt"};
const slide = slides[0];
slide.getPageElements().forEach(e => {
const type = e.getPageElementType();
if (type == SlidesApp.PageElementType.SHAPE) {
const shape = e.asShape();
shape.removeLink();
shape.getText().getLinks().forEach(l => l.getTextStyle().removeLink());
} else if (type == SlidesApp.PageElementType.TABLE) {
const table = e.asTable();
const rows = table.getNumRows();
const cols = table.getNumColumns();
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
table.getCell(r, c).getText().getLinks().forEach(l => l.getTextStyle().removeLink());
}
}
} else {
if (type in otherTypes) e[otherTypes[type]]().removeLink();
}
});
}
- 如果您使用Google幻灯片的容器绑定脚本,也可以使用
SlidesApp.getActivePresentation().getSlides()
代替const slides = SlidesApp.openById("###").getSlides()
. - 在此示例脚本中,将删除Google幻灯片中第一张幻灯片中所有文本和所有对象的所有超链接.形状和表格中的文本将被删除.
- If you use the container-bound script of the Google Slides, you can also use
SlidesApp.getActivePresentation().getSlides()
instead ofconst slides = SlidesApp.openById("###").getSlides()
. - In this sample script, all hyperlinks of all texts and of all objects in the 1st slide in the Google Slides are deleted. The texts in the shape and tables are deleted.
- 请将此脚本与V8配合使用.
-
如果要删除Google幻灯片中所有幻灯片中的所有超链接,可以使用以下脚本.
- Please use this script with V8.
If you want to delete all hyperlinks in all slides in a Google Slides, you can use the following script.
function myFunction() {
const slides = SlidesApp.openById("###").getSlides(); // Please set the Slides ID.
const otherTypes = {"IMAGE": "asImage", "LINE": "asLine", "SHEETS_CHART": "asSheetsChart", "WORD_ART": "asWordArt"};
slides.forEach(s => {
s.getPageElements().forEach(e => {
const type = e.getPageElementType();
if (type == SlidesApp.PageElementType.SHAPE) {
const shape = e.asShape();
shape.removeLink();
shape.getText().getLinks().forEach(l => l.getTextStyle().removeLink());
} else if (type == SlidesApp.PageElementType.TABLE) {
const table = e.asTable();
const rows = table.getNumRows();
const cols = table.getNumColumns();
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
table.getCell(r, c).getText().getLinks().forEach(l => l.getTextStyle().removeLink());
}
}
} else {
if (type in otherTypes) e[otherTypes[type]]().removeLink();
}
});
});
}
- removeLink() in Class Shape
- removeLink() in Class TextStyle
这篇关于使用GAS删除Google幻灯片的所有超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!