Reputation: 33
I have an issue with Google Apps Script. I have a slide link of Google Slides in a Google Sheets file. I made a copy of both files and I want to update the slide link in the sheet with the new one. Could you help me to find a solution to do it? Because I didn't achieve it.
Upvotes: 2
Views: 2316
Reputation: 2598
With the following code you can accomplish your objective; that is to insert into the cell B5
the URL of the third slide. You only need to insert into the code the required IDs and to activate SlidesApp using Resource ⮞ Advanced Google services ⮞ Slides ⮞ On
.
function insertSlideURL() {
var sheet = SpreadsheetApp.openById(
"{SPREADSHEET ID}").getSheetByName("Sheet1");
var cell = "B5";
var presentation = SlidesApp.openById(
"{PRESENTATION ID}");
var slides = presentation.getSlides();
var slide = 3;
var slideURL = presentation.getUrl() + "#slide=id." + slides[slide - 1]
.getObjectId();
sheet.getRange(cell).setValue(slideURL);
}
I hope that this fulfills your requirements. You can change the cell and slide variables to fit another cell/slide configuration.
For more clarification: I used getSlides()
to gather an array of every slide and getObjectId()
to read its ID. Please, write me back if you need further help or more clarification.
Upvotes: 1
Reputation: 7377
You need to construct the slide URL manually, using the Object ID from Slide.getObjectID()
Here is an example which will log the URL's for each slide in a presentation.
function getSlideURLS() {
var presentation = SlidesApp.getActivePresentation();
var base_url = presentation.getUrl();
var slides = presentation.getSlides();
for(var i in slides){
var slide_url = base_url+'#slide=id.'+slides[i].getObjectId();
Logger.log(slide_url);
}
}
Upvotes: 1