允许通过SlidesApp 或幻灯片 API 控制指南的功能请求已提交至issue tracker。如果您觉得该功能有用,请加注星标。
简答
如前所述,不幸的是,这目前无法通过SlidesApp 服务或Slides API 实现。
解决方法
实际上可以通过传递一个负整数作为insertLine 的参数来使线条延伸到幻灯片边界之外。至于是否可以删除线,如果将指南拖出幻灯片边界,用户也可以“删除”指南。
我无法模仿的指南的唯一属性是在呈现时隐藏它们(因为隐藏了真正的指南)。
以下是类似于您的方法的解决方法(创建Lines 的网格):
指南
/**
* @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));
演示