通过 Google Apps 脚本获取 Google 演示幻灯片的布局显示名称

问题描述 投票:0回答:1

我正在尝试将一张新幻灯片附加到我的演示文稿中,其中包含通过 Google Apps 脚本创建的布局。

我开始了一个新的演示文稿,创建了两个新布局,将它们命名为“BulletDescription”和“TextDescription”。 我可以获得演示文稿中所有可用的布局。但是,我找不到我按其名称手动创建的布局。

function AddNewSlideToPresentation(LayoutType) //LayoutType = 'BulletDescription'
{ 
  var presentation = SlidesApp.openById('PresentationID');
  var layouts = presentation.getLayouts();
  var selectedLayout;
  for(var item in layouts)
  {
    Logger.log(layouts[item].getLayoutName());
    if(layouts[item].getLayoutName() == LayoutType)
    {
      selectedLayout = layouts[item];
    }
  }

  var newSlide = presentation.appendSlide(selectedLayout); // this returns an error
}

似乎 .getLayoutName() 函数为我们提供了与我在日志中发现的不同的名称;

TITLE
SECTION_HEADER
TITLE_AND_BODY
MAIN_POINT
.
.
CUSTOM_1
CUSTOM_2

我相信

CUSTOM_1
CUSTOM_2
是我创造的。有没有办法通过 Google Apps 脚本获取布局的显示名称?

google-apps-script presentation google-slides
1个回答
0
投票

尝试从 LayoutProperties 获取布局名称:

if (layouts[item].layoutProperties.displayName == LayoutType)
{
    // found needed layout..
}
© www.soinside.com 2019 - 2024. All rights reserved.