![](/img/trans.png)
[英]I need to reverse the selected slide order using Google Apps script
[英]Apps script to format selected text on a Google Slide
我正在嘗試創建一個腳本來格式化 Google 幻燈片上的選定文本(由用戶使用鼠標選擇)。 例如,腳本可能會將所選文本更改為 Arial 字體,字號 11,左對齊。
我知道如何創建一個新的菜單項來在幻燈片中運行腳本 - 所以我已經解決了這部分難題。
我試過轉換為 Google 表格創建的類似腳本......但它似乎不適用於幻燈片。
這是我到目前為止所擁有的:
function onOpen() {
let ui = SlidesApp.getUi();
ui.createMenu('Macros').addItem('ParagraphFormat',
'ParagraphFormat').addToUi();
};
function ParagraphFormat() {
var slide = SlidesApp.getActivePresentation();
slide.getSelection()
.setFontSize(11)
.setFontFamily('Arial');
};
我相信你的目標如下。
getSelection()
返回 Class 選擇。 在這種情況下,沒有setFontSize
和setFontFamily
方法。 我認為這就是您當前問題的原因。 當你想對選中的文字使用setFontSize
和setFontFamily
時,下面的修改怎么樣?
slide.getSelection()
.setFontSize(11)
.setFontFamily('Arial');
var textRange = slide.getSelection().getTextRange();
if (textRange) {
textRange.getTextStyle().setFontSize(11).setFontFamily('Arial');
}
setFontSize
和setFontFamily
反映在所選文本中。 關於您的新問題“ One more cheeky question: how would I add one more property to align the text to the left? (eg. adding.setTextAlignment('left')... but this doesn't work)
One more cheeky question: how would I add one more property to align the text to the left? (eg. adding.setTextAlignment('left')... but this doesn't work)
,在當前階段,只有部分文本文本框的文本無法對齊。 因此,在這種情況下,可以對齊所選文本的段落。 如果你想這樣做,下面的示例腳本怎么樣?
var textRange = slide.getSelection().getTextRange();
if (textRange) {
textRange.getTextStyle().setFontSize(11).setFontFamily('Arial');
textRange.getParagraphStyle().setParagraphAlignment(SlidesApp.ParagraphAlignment.START);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.