如何在Google幻灯片上添加具有新布局的新幻灯片? [英] How to add a new slide with new layout on Google Slides?

查看:160
本文介绍了如何在Google幻灯片上添加具有新布局的新幻灯片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我所做的:

  1. 在Google幻灯片上创建了新的演示文稿,

  1. Created a new presentation on Google Slides,

在以下位置的主布局"视图上编辑了预定义的布局之一为了有一个我要使用的新布局,

Edited one of the predefined layouts on the Master Layout view in order to have a new layout that I want to use,

将主版式的名称修改为会议",

Edited the name of the Master Layout to "Meeting",

编辑了我要用于的预定义布局的名称办公室".

Edited the name of the predefined layout that I want to use to "Office".

我的问题是我无法在Google Script上引用我要使用的特定预定义布局.

My problem is that on Google Script I am not being able to reference this specific predefined layout that I want to use.

到目前为止,我的代码如下:

So far, my code is the following:

function AddSlideToPresentatio() {

// The following line opens my presentation
var presentation = SlidesApp.openById('PresentationID');

//Now, I try to use my new layout
  presentation.appendSlide("Office");
}

我绝对不知道为什么这行不通.当我尝试运行它时,出现错误:

I have absolutely no idea on why this doesn't work. When I try to run it, I get the error:

"找不到方法appendSlide(string).(第6行,文件"Office").

"Cannot find method appendSlide(string). (line 6, file "Office").

以下是我尝试过的一些组合,它们也给我带来类似的错误:

The following are some of the combinations that I tried, and they get me similar errors:

presentation.appendSlide('Office');
presentation.appendSlide(Office);
presentation.appendSlide("Meeting - Office");
presentation.appendSlide('Meeting - Office');
presentation.appendSlide(Meeting - Office);

如果我只使用 presentation.appendSlide(),它将创建一个新幻灯片,但不会使用我要使用的布局.

If I just use presentation.appendSlide() it creates a new slide, but not with the layout that I want to use.

Google Apps脚本参考中,有三个方法:

  1. appendSlide(),
  2. appendSlide(layout)
  3. appendSlide(predefinedLayout)

但是,我似乎无法理解最后两个之间的区别,因为当我尝试使用它们时,它们似乎在做相同的事情.

However, I can't seem to understand what is the difference between that last two, because when I try to use them they seem to do the same thing.

推荐答案

您正在传递 appendSlide 方法的布局对象名称,但您应该传递

You are passing layout object's name for the appendSlide method, but you should pass LayoutObject parameter.

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 是一个枚举.它包含演示文稿中常见的布局.阅读所有可用的预定义的布局

PreDefinedLayout is an enum. It contains layouts that commonly found in presentations. Read all the available predefined layouts

按如下所述使用它们;

use them as below;

presentation.appendSlide(SlidesApp.PredefinedLayout.SECTION_TITLE_AND_DESCRIPTION);

这篇关于如何在Google幻灯片上添加具有新布局的新幻灯片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆