Apps Scriptリファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2024年4月15日月曜日

Google Apps Scriptでスライド内のページIDを取得したい(.getObjectId)


GoogleスライドのURL末尾にあるslide=id.に続くidを取得したくて書いたコードです。


サンプルのURL→ https://docs.google.com/presentation/d/SLIDE_ID/edit#slide=id.g2cc2c94e9c6_0_0





Code.gs
function getPageIds() {
const url = 'https://docs.google.com/presentation/d/SLIDE_ID/edit#slide=id.p';
const slide = SlidesApp.openByUrl(url);
const pages = slide.getSlides();
const pageIds = [];
for(let i = 0; i < pages.length; i++) {
const pageId = pages[i].getObjectId();
pageIds.push(pageId);
}
Logger.log(pageIds)
}



実行結果


サンプルのスライドには5枚存在するため、5つのidがログに出ています。
1枚目のidは p になるらしい。



Reference

Class Page > getObjectId() 

Latest post

スプレッドシートの空白セルを直前の値で埋めたい

A列の空白セルに直前の値を入れたくて書いたコードです スプレッドシートに以下のようなBeforeの表があるとき (A列に空白セルがある) Before 1 A B 2 エリア 都市 3 東京 新宿 4 渋谷 5 池袋 6 神奈川 横浜 7 川崎 8 相模原 9 千葉 千葉 10 ...