问题描述
我需要创建很多幻灯片,因此决定编写一段脚本,使用标头样式自动从google docs文本文档中创建google幻灯片(例如:H1成为新的幻灯片标题,下面的所有文本将变成幻灯片上的文本。
我搜索了这个问题,但是没有找到合适的解决方案,并且我也不精通自己解决问题。
在一些帮助下,我到了这一步:
function SlideMaker() {
Presentation = SlidesApp.create("Presentation.2020.08.XX.AA.v58") // Creates an empty Title slide only
// Missing: Lets add title text from google docs (low priority).
doc = DocumentApp.openById("1OaLg5bpQr6qZEKpaBef7H8vnqSn8WwGPsGn1ewRmkSo") //id for your document (you find it in the documents URL)
body = doc.getBody()
p = body.getParagraphs()
while( item = p.shift() ) { // foreach paragraph
console.log(item.getText())
if(item.getheading() == DocumentApp.Paragraphheading.heading1){
console.log("is H1")
slide = Presentation.appendSlide() // create a new slide
console.log("is TEXT")
var shape = slide.insertShape(SlidesApp.ShapeType.TEXT_Box,40,30,600,60);
var textRange = shape.getText();
textRange.setText(item.getText()); // put the text on the new slide
// Problem: Pasted text is put in a new textBox,instead of writing into the appropriate field (into slide header; high priority).
} else if (item.getText() == "") { // do nothing at empty lines
} else {
console.log("is TEXT")
// Problem: Too many Pasted textBoxes,per paragraph. E.g. a bulletpointed list is split (high priority)
// Problem: Pasted textBoxes overlap (medium priority)
var shape = slide.insertShape(SlidesApp.ShapeType.TEXT_Box,90,300);
var textRange = shape.getText();
textRange.setText(item.getText()); // put the text on the new slide
}
}
}
此脚本保存在google文档中的脚本编辑器下并从中运行。
您可以看到the input document here和the resulting Slides are here。要查看输出的动态变化,您必须复制文档,因为它会将新幻灯片放到自己的主目录中。
与当前脚本一起发布
- 当前粘贴未将文本粘贴到适当的字段中:幻灯片标题和幻灯片正文
- 这意味着您在Google幻灯片中应用的布局和主题不起作用。
- 因此,目前必须手动定义格式的每一位。那是行不通的。
- 我应该创建某种类型的幻灯片并将文本插入相关字段中。
- 因此,目前必须手动定义格式的每一位。那是行不通的。
- 当前脚本将每个新段落粘贴到单独的文本框中。
- 当前,此列表按行划分
- 是否需要类似appendText(text)的内容?
- 脚本可以在“两个H1行之间的完整文本块”上进行迭代吗?
- 是否可以格式化粘贴的文本?例如: H1→幻灯片标题样式
https://developers.google.com/slides/how-tos/styling#python是有用的参考
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)