使用Google幻灯片中的应用脚本将pageElement放在前面或后面 [英] Bring the pageElements to front or back using apps script in Google Slides

查看:128
本文介绍了使用Google幻灯片中的应用脚本将pageElement放在前面或后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

堆叠顺序取决于将它们插入幻灯片的顺序.但是,幻灯片中的某些页面元素仍处于隐藏状态.

The stacking order is determined by the order by which they are inserted into the slide. However, some of the page elements in slides remain hidden.

是否可以使用应用脚本更改Google幻灯片中对象的顺序?

Is there a way to change the Order of objects in Google slides using apps script?

推荐答案

此解决方法如何?我也遇到过同样的情况.当时,我已经使用此替代方法移动了该元素.我认为对于这种情况有几种解决方法.因此,请将此视为其中之一.此解决方法的流程如下.

How about this workaround? I have experienced the same situation with you. At that time, I have moved the element using this workaround. I think that there are several workarounds for this situation. So please think of this as one of them. The flow of this workaround is as follows.

例如,在Google幻灯片中,当为幻灯片创建新形状时,会将其添加到pageElements的最后一个元素中.这意味着pageElements的最后一个元素是最前面的.此方法用于解决方法.

In Google Slides, for example, when new shape is created to a slide, it is added to the last element to pageElements. This means that the last element to pageElements is the most front. This is used for the workaround.

  1. 选择形状.
    • 在这种情况下,作为示例,通过单击选择显示在最前面的形状.
  1. Select shapes.
    • In this case, as a sample, the shapes which are brought to the front are selected by click.

通过这种方式,可以将选定的形状带到最前面和后面.当该流程反映到脚本时,它如下所示.

By this, the selected shapes can be brought to the most front and back. When this flow is reflected to the script, it becomes as follows.

function move(page, spe) {
  var pe = page.getPageElements();
  spe.forEach(function(e) {
    page.insertPageElement(e);
  });
  pe.forEach(function(f, i) {
    if (spe.some(function(g) {return f.getObjectId() == g.getObjectId()})) {
      pe[i].remove();
    }
  });
}

// Bring to back
function back() {
  var slide = SlidesApp.getActivePresentation();
  var selected = slide.getSelection();
  var page = selected.getCurrentPage();
  var pageElements = page.getPageElements();
  var selectedPageElements = selected.getPageElementRange().getPageElements();
  var noSelectedPageElements = pageElements.filter(function(e) {return !selectedPageElements.some(function(f) {return e.getObjectId() == f.getObjectId()})});
  move(page, noSelectedPageElements);
}

// Bring to front
function front() {
  var slide = SlidesApp.getActivePresentation();
  var selected = slide.getSelection();
  var page = selected.getCurrentPage();
  var pageElements = page.getPageElements();
  var selectedPageElements = selected.getPageElementRange().getPageElements();
  move(page, selectedPageElements);
}

结果:

  • 使用此脚本时,请首先在幻灯片上选择形状.然后运行front()back().运行front()时,所选形状将移到最前面.运行back()时,它会移到最靠后的位置.
  • 在此示例脚本中,所选形状被带到最前面和后面.这是一个简单的示例脚本.
    • 如果要移动每个元素的形状,请修改脚本.
    • When you use this script, at first, please select the shapes on a slide. Then run front() or back(). When front() is run, the selected shape is moved to the most front. When back() is run, it is moved to the most back.
    • In this sample script, the selected shapes are brought to the most front and back. This is a simple sample script.
      • If you want to move the shapes every element, please modify the script.
      • insertPageElement(pageElement)
      • remove()

      如果这个答案不是您想要的,对不起.

      If this answer was not what you want, I'm sorry.

      幻灯片服务在Google更新于2018年11月14日进行了更新,其中有几种方法为解决此问题而添加了.

      通过以下新方法扩展了幻灯片服务,该方法使您可以控制幻灯片中页面元素的Z位置.

      The Slides service has been extended with the following new methods that let you control the Z-positioning of page elements in Slides.

      • bringForward()
      • bringToFront()
      • sendBackward()
      • sendToBack()
      • bringForward()
      • bringToFront()
      • sendBackward()
      • sendToBack()

      这篇关于使用Google幻灯片中的应用脚本将pageElement放在前面或后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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