我相信你的目标如下。
- Q1。您想知道脚本问题的原因。
- Q2。您想使用 Google Apps 脚本删除 Google 幻灯片中幻灯片中的所有超链接。
为此,这个答案怎么样?
A1:
在您的脚本中,setLinkUrl(null)用于删除链接。这是你的问题的原因。在这种情况下,请使用removeLink()代替setLinkUrl(null)。参考
A2:
在您的脚本中,您尝试删除第一页上第一个形状中文本的第一个超链接。这是你的问题的原因。为了在 Google 幻灯片中删除幻灯片中的所有超链接,下面的示例脚本怎么样?
示例脚本:
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 幻灯片中第一张幻灯片中所有文本和所有对象的所有超链接。形状和表格中的文本被删除。
笔记:
- 请将此脚本与 V8 一起使用。
如果要删除 Google 幻灯片中所有幻灯片中的所有超链接,可以使用以下脚本。
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();
}
});
});
}
参考: