您可以将脚本分配给页面元素(形状等)吗? [英] Can you assign scripts to page elements (shapes etc.)?
问题描述
我想为学生制作交互式幻灯片.
I want to make an interactive slideshow for students.
我想添加形状,因此当您单击该形状时,它将运行Apps脚本脚本.在Google表格中可以做到这一点.
I want to add shapes, so when you click on the shape it will run an Apps Script script. This is possible in Google Sheets.
所以,我认为您也可以使用幻灯片来做.
So, I thought that you could do it with slides as well.
推荐答案
无法运行网络应用程序在打开时运行您的脚本.例如,这是一个网络应用程序的脚本,只要有人访问它,它就会更改第一张幻灯片的第一个形状上的文本.
There is no way to run a container-bound script by clicking a shape in Google Slides like you can in Google Sheets. But, you can accomplish a similar effect by adding a shape with a link to a web app that runs your script when opened. For Example, here is a script for a web app that changes the text on the first shape of the first slide whenever someone visits it.
function doGet() {
const presentation = SlidesApp.openById(id); // presentation id
const slide = presentation.getSlideById(id); // slide id
const textBox = slide.getShapes().filter(_s => _s.getObjectId() === objectId)[0].getText(); // id of your text box object
const clicks = Number(textBox.asString());
textBox.setText(clicks + 1);
return ContentService.createTextOutput("Thanks for clicking!"); //message to display when user visits your webapp
}
这是一个有效的示例: 带有可点击按钮的Google幻灯片演示
Here is a working example: Google Slide Presentation with Clickable Button
这篇关于您可以将脚本分配给页面元素(形状等)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!