问题描述
有什么方法可以控制Google幻灯片演示文稿中的指南(第三条规则)。据我阅读的Google Apps脚本文档,还没有控制指南的方法。
我已经尝试过像指南一样的行(第三条规则),但是这些不是“真实的”指南。用户可以删除这些行,并且这些行仅限于幻灯片页面区域。
要启用指南(第三条规则),请点击此处:
解决方法
允许通过
SlidesApp
或Slides API控制指南的功能请求已提交到issue tracker。如果发现该功能有用,请加注星标。
简短答案
很遗憾,如前所述,目前无法通过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,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,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));
演示
,幻灯片指南当前无法通过编程方式进行管理。
指南是对幻灯片(since April '18)的最新补充,尚未在Slides API上实现,更不用说在Apps Script上了。目前,管理它们的唯一方法是通过“幻灯片”编辑器手动进行。
提交功能请求:
我建议您在this Issue Tracker component上提交有关此功能在Slides API上的实现的功能请求。我对该组件进行了一些研究,似乎还没有人要求这样做。
完成后,您至少可以在实现Apps Script内置类和方法之前,通过Advanced Slides Service从Apps Script中进行管理。