在Google Apps脚本中获取幻灯片标题

编程入门 行业动态 更新时间:2024-10-11 09:19:20
本文介绍了在Google Apps脚本中获取幻灯片标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试编写一个Google Apps脚本,该脚本采用每张幻灯片的幻灯片标题(因为它们在主幻灯片中),并将它们放在幻灯片2上格式良好的目录中.

I'm attempting to write a google apps script that takes the slide titles of every slide (as they are in the master slides) and put them in a nicely formatted table of contents on slide 2.

不一定必须使用apps脚本来完成,但这是我能想到的最好方法.

It doesn't necessarily have to be done with apps script, but this is the best way I could think of.

function readPageElementIds(presentationId, pageId) { var response = Slides.Presentations.get( presentationId); Logger.log(response.slides) for (var i = 0; i < response.slides.length; i++) { var slide = response.slides[i].pageElements; for (var j = 0; j < slide.length; j++) { if (slide[j].shape) { var texts = slide[j].shape.text.textElements; for (var k = 0; k < texts.length; k++) { if (texts[k].autoText) { Logger.log(texts[k].autoText.content); } } } } } }

是的,有很多for循环,我不知道该怎么做.

Yes that's a lot of for loops, I have no idea how to do this.

推荐答案

那已经很接近了.您缺少的东西:

That's fairly close. Things you're missing:

  • 您要遍历所有形状,而不仅仅是标题.为此,请过滤shape.placeholder.type属性.您只想查看具有TITLE和CENTERED_TITLE占位符类型的形状.

  • You're iterating on all of the shapes, not just the titles. For that, filter on the shape.placeholder.type property. You only want to look at shapes with TITLE and CENTERED_TITLE placeholder types.

autoText文本元素相对较少.您的大部分文本都将包含在TextRun文本元素中

autoText text elements are relatively rare. Most of your text will be in TextRun text elements

此代码将起作用:

function readPageElementIds(presentationId, pageId) { var response = Slides.Presentations.get( presentationId); Logger.log(response.slides) for (var i = 0; i < response.slides.length; i++) { var slide = response.slides[i].pageElements; for (var j = 0; j < slide.length; j++) { if (slide[j].shape && slide[j].shape.placeholder && (slide[j].shape.placeholder.type == 'TITLE' || slide[j].shape.placeholder.type == 'CENTERED_TITLE')) { var texts = slide[j].shape.text.textElements; var shapeText = ""; for (var k = 0; k < texts.length; k++) { if (texts[k].autoText) { shapeText += texts[k].autoText.content; } if (texts[k].textRun) { shapeText += texts[k].textRun.content; } } Logger.log(shapeText); } } } }

更多推荐

在Google Apps脚本中获取幻灯片标题

本文发布于:2023-10-31 10:05:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545762.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:幻灯片   脚本   标题   Google   Apps

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!