I've created a bit of a script that allows me to use data stored in a Google Sheet to generate a set of Google Slides (based on a pre-formatted template slide).
PreviousTarget
and CurrentTarget
in the script below reference cells that are formatted as Date cells within Google Sheets. The format defined is dd/mm/yyyy. When I run the script, the correct dates are injected into the Google Slide, however, instead of the dd/mm/yyyy formatting, they look like this:
Sun Jul 26 2020 00:00:00 GMT+0100 (British Summer Time)
I can resolve the issue via changing the formatting of the two cells to a plain text string within the Google Sheet. But is there a way to reformat the dates during the running of the script?
Any ideas how I can fix the formatting during the injection to Google Slides?
var dataSpreadsheetUrl = ""; //sorry, I removed link to the sheet here as it contained sensitive information
var ss = SpreadsheetApp.openByUrl(dataSpreadsheetUrl);
var deck = SlidesApp.getActivePresentation();
var sheet = ss.getSheetByName('1 - Project Overview');
var values = sheet.getRange('A3:R').getValues();
var slides = deck.getSlides();
var templateSlide = slides[1];
var presLength = slides.length;
values.forEach(function(page){
if(page[1]){
var Project = page[1];
var Lead = page [4]
var RagStatus = page[5];
var Trend = page[6];
var Objectives = page[9];
var Summary = page[10];
var PreviousTarget = page[11];
var CurrentTarget = page[12];
var Risk1 = page[14];
var Risk2 = page[15];
var Issue1 = page[16];
var Issue2 = page[17];
templateSlide.duplicate(); //duplicate the template page
slides = deck.getSlides(); //update the slides array for indexes and length
newSlide = slides[2]; // declare the new page to update
var shapes = (newSlide.getShapes());
shapes.forEach(function(shape){
shape.getText().replaceAllText('{{Project}}',Project);
shape.getText().replaceAllText('{{Lead}}',Lead);
shape.getText().replaceAllText('{{Objectives}}',Objectives);
shape.getText().replaceAllText('{{Summary}}',Summary);
shape.getText().replaceAllText('{{PreviousTarget}}',PreviousTarget);
shape.getText().replaceAllText('{{CurrentTarget}}',CurrentTarget);
shape.getText().replaceAllText('{{RagStatus}}',RagStatus);
shape.getText().replaceAllText('{{Trend}}',Trend);
shape.getText().replaceAllText('{{Risk1}}',Risk1);
shape.getText().replaceAllText('{{Risk2}}',Risk2);
shape.getText().replaceAllText('{{Issue1}}',Issue1);
shape.getText().replaceAllText('{{Issue2}}',Issue2);
});
presLength = slides.length;
newSlide.move(presLength);
} // end our conditional statement
}); //close our loop of values
//Remove the template slide
templateSlide.remove();
} ```