下面是我做的:
在 Google 幻灯片上创建了一个新的演示文稿,
编辑了 Master Layout View 中的一个预定义布局 为了有一个我想使用的新布局,
将主布局的名称编辑为“ session ”,
编辑了我想要使用的预定义布局的名称 “办公室”。
我的问题是,在 Google Script 上,我无法引用我想要使用的这个特定的预定义布局。
到目前为止,我的代码如下:
function AddSlideToPresentatio() {
// The following line opens my presentation
var presentation = SlidesApp.openById('PresentationID');
//Now, I try to use my new layout
presentation.appendSlide("Office");
}
我完全不知道为什么这不起作用。当我尝试运行它时,出现错误:
"Cannot find method appendSlide(string). (line 6, file "Office").
以下是我尝试过的一些组合,它们给我带来了类似的错误:
presentation.appendSlide('Office');
presentation.appendSlide(Office);
presentation.appendSlide("Meeting - Office");
presentation.appendSlide('Meeting - Office');
presentation.appendSlide(Meeting - Office);
如果我只使用 presentation.appendSlide()
它会创建一张新幻灯片,但不会使用我想要使用的布局。
在Google Apps Script Reference共有三种方法:
- appendSlide(),
- appendSlide(布局),
- appendSlide(预定义布局)
但是,我似乎无法理解最后两者之间的区别,因为当我尝试使用它们时,它们似乎做同样的事情。
最佳答案
您正在为 appendSlide 方法传递布局对象的名称,但您应该传递 LayoutObject
参数。
appendSlide(LayoutObject)
// The following line opens my presentation
var presentation = SlidesApp.openById('PresentationID');
// this will return an array of all the layouts
var layouts = presentation.getLayouts();
//if your first array item is the office layout
var newSlide = presentation.appendSlide(layouts[0]);
//Orelse you can search for your layout
var selectedLayout;
for(var item in layouts)
{
//Logger.log(layouts[item].getLayoutName());
if(layouts[item].getLayoutName() =='CUSTOM_1')
{
selectedLayout = layouts[item];
}
}
var newSlide = presentation.appendSlide(selectedLayout);
PreDefinedLayout
是一个枚举。它包含演示文稿中常见的布局。阅读所有可用的 predefined layouts
如下使用它们;
presentation.appendSlide(SlidesApp.PredefinedLayout.SECTION_TITLE_AND_DESCRIPTION);
关于javascript - 如何在 Google 幻灯片上添加具有新布局的新幻灯片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47386726/