5

我正在尝试使用通过 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 脚本获取布局的显示名称?

4

1 回答 1

0

试试这个从LayoutProperties获取布局名称:

if (layouts[item].layoutProperties.displayName == LayoutType)
{
    // found needed layout..
}
于 2020-06-23T20:33:11.660 回答