google-apps-script - 如何以编程方式控制指南(第三规则)?
问题描述
有什么方法可以控制 Google 幻灯片演示文稿中的指南(第三规则)。据我阅读 Google Apps 脚本文档,没有方法可以控制指南。
我已经尝试过类似于指南(第三规则)的线条,但这些不是“真正的”指南。用户可以删除这些行,这些行仅限于幻灯片页面区域。
查看图片以了解线条和指南之间的区别(第三规则):
要启用指南(第三规则),请访问此处:
解决方案
允许通过
SlidesApp
或 Slides API 控制指南的功能请求已提交给问题跟踪器。如果您发现该功能有用,请加注星标。
简短的回答
如前所述,不幸的是,这目前无法通过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));
演示
推荐阅读
- javascript - 在 jQuery 自动完成中设置下拉菜单的文本
- flutter - 如何将下拉菜单中选择的值传递给 Flutter/Dart 中它正下方的有状态小部件?
- ruby-on-rails - 如何防止用户被保存在 ruby on rails 中关联模型的验证中?
- reactjs - Ant Design 表格的行应该是复选框
- javascript - 对于 4,5 或 6 等恒定长度的 javascript 循环,但不适用于 carts.length
- asterisk - 仅提取 Asterisk 上的注册联系信息
- netbeans - Netbeans Msys2 使 Cygwin1.dll 问题
- flutter - 选择项目时,颤振不更新放置在对话框中的 DropdownButton
- windows-10 - Windows 上的 Netbeans 12 不允许我连接 Tomcat
- pytorch - 如何将 AMD GPU 用于 fastai/pytorch?