gpt4 book ai didi

google-apps-script - 如何以编程方式控制指南(第三规则)?

转载 作者:行者123 更新时间:2023-12-04 00:16:23 25 4
gpt4 key购买 nike

有什么方法可以控制 Google 幻灯片演示文稿中的指南(第三规则)。据我阅读 Google Apps 脚本文档,没有控制指南的方法。

我已经尝试过表现得像指南的线条(第三条规则),但这些不是“真正的”指南。用户可以删除这些行,这些行仅限于幻灯片页面区域。

请看图片了解线和指南之间的区别(第三条规则):

lines and guides difference

要启用指南(第三规则),请转到此处:

guides

最佳答案

A feature request to allow guides to be controlled via SlidesApp or Slides API is submitted to the issue tracker. Please star it if you find that the feature would be useful.

简答

如前所述,不幸的是,目前还不能通过 SlidesApp服务或Slides API .

解决方法

实际上可以通过传递一个负整数作为insertLine 的参数来使线条延伸到幻灯片边界之外。 .至于是否可以删除线,如果将指南拖出幻灯片边界,用户也可以“删除”指南。

我无法模仿的指南的唯一属性是在呈现时隐藏它们(因为隐藏了真正的指南)。

以下是类似于您的方法的解决方法(创建 Line s 的网格):

指南

/**
* @summary emulates adding guides to the Slide
*
* @param {{
* rows : (number|1),
* deleteOld : (boolean|true),
* cols : (number|1),
* color : string
* }}
*/
const showGuides = ({ deleteOld = true, rows = 1, cols = 1, color = "#d3d3d3" } = {}) => {

const presentation = SlidesApp.getActivePresentation();
const currPage = presentation.getSelection().getCurrentPage();

const prop = "guides";

const store = PropertiesService.getUserProperties();

/** @type {string[]} */
let guideRefs = JSON.parse(store.getProperty(prop) || "[]");

const lines = currPage.getLines();

const oldLines = lines.filter((line) => guideRefs.includes(line.getObjectId()));

if (deleteOld) {
oldLines.forEach(line => line.remove());

guideRefs = removeElements(guideRefs, oldLines.map(l => l.getObjectId()));
}

const currWidth = presentation.getPageWidth();
const currHeight = presentation.getPageHeight();

const xStep = Math.floor(currWidth / cols);
const yStep = Math.floor(currHeight / rows);

const newGuides = [];

const maxScreen = 4096;

for (let x = 0; x <= cols; x++) {
const line = currPage.insertLine(
SlidesApp.LineCategory.STRAIGHT,
xStep * x, -maxScreen, xStep * x, currHeight + maxScreen
);

const fill = line.getLineFill();
fill.setSolidFill(color);

const oid = line.getObjectId();
guideRefs.push(oid);
newGuides.push(line);
}

for (let y = 0; y <= rows; y++) {
const line = currPage.insertLine(
SlidesApp.LineCategory.STRAIGHT,
-maxScreen, yStep * y, currWidth + maxScreen, yStep * y
);

const fill = line.getLineFill();
fill.setSolidFill(color);

const oid = line.getObjectId();
guideRefs.push(oid);
newGuides.push(line);
}

store.setProperty(prop, JSON.stringify(guideRefs));
};

实用程序

/**
* @summary removes elements from an array
* @param {any[]} arr
* @param {...any} elems
* @returns {any[]}
*/
const removeElements = (arr, ...elems) => arr.filter((elem) => !elems.includes(elem));

演示

workaround test

关于google-apps-script - 如何以编程方式控制指南(第三规则)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63584195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com