MCPcopy Create free account
hub / github.com/analyticswithadam/App_Script / transferCharts

Function transferCharts

EndtoEndAutomatedDecks.js:179–245  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

177
178
179function transferCharts() {
180 // Open the Google Slides deck where you want to transfer the charts
181 var slidesDeck = SlidesApp.openById("1zS2VBQwungFdf-pktG1qdNiHzmeXPlgTO18CKe903bU");
182
183 // Open the 'Output' sheet from the active Google Sheet
184 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Output');
185
186 // Get the first slide
187 var slide = slidesDeck.getSlides()[0];
188
189 // Clear existing images and text boxes on the slide except the header icon
190 var elements = slide.getPageElements();
191 elements.forEach(function(element) {
192 var topPosition = element.getTop();
193
194 if (element.getPageElementType() === SlidesApp.PageElementType.IMAGE) {
195 // Remove images that are below the header (assuming header is within top 150 pixels)
196 if (topPosition > 99) {
197 element.remove();
198 }
199 } else if (element.getPageElementType() === SlidesApp.PageElementType.SHAPE) {
200 // Remove text boxes that are below the header
201 if (topPosition > 99) {
202 element.remove();
203 }
204 }
205 });
206
207 // Get the chart from the sheet and insert it into the slide
208 var charts = sheet.getCharts();
209 if (charts.length > 0) {
210 var chart = charts[0]; // Get the first chart (assuming it's the only one)
211
212 // Get the chart as a blob image
213 var image = chart.getAs('image/png');
214
215 // Insert the image into the slide
216 slide.insertImage(image).setLeft(30)
217 .setTop(100)
218 .setWidth(400)
219 .setHeight(250);;
220 } else {
221 Logger.log('No charts found on the sheet.');
222 }
223
224 // Get the narrative from cell J3
225 var narrative = sheet.getRange('J3').getValue();
226
227 // Insert the narrative into the slide as a text box
228 if (narrative) {
229 var textBox = slide.insertTextBox(narrative);
230 // Adjust the position and size of the text box as needed
231 textBox.setLeft(450);
232 textBox.setTop(140);
233 textBox.setWidth(200);
234 textBox.setHeight(150);
235
236 // Optional: Set text style

Callers 1

generateReportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected