使用Rails创建一份PowerPoint演示文稿

5

我处于这样一种情况,必须通过编程构建PowerPoint演示文稿,并通过Web应用程序提供生成的ppt文件,最好使用Rails、JavaScript或Ruby。这是否可行?如果可以,如何以及使用哪些工具?

我对如何最好地解决这个问题的任何建议都持开放态度。谢谢!


1
需要是PowerPoint文件吗?还是创建一个在全屏浏览器中运行的HTML演示文稿就足够了? - Bergi
好的,你是在谈论服务器端JavaScript吗? - Bergi
或者客户端。我不反对使用Node或类似的东西。 - MalSu
创作过程中需要客户端完成哪些部分?难道不只是下载吗? - Bergi
你也可以看一下 https://github.com/pythonicrubyist/powerpoint - Dofs
显示剩余9条评论
2个回答

6
这个 Ruby Gem 似乎比当前被接受的答案中提到的那个更成熟。

https://github.com/pythonicrubyist/powerpoint http://rubygems.org/gems/powerpoint

require 'powerpoint'

@deck = Powerpoint::Presentation.new

# Creating an introduction slide:
title = 'Bicycle Of the Mind'
subtitle = 'created by Steve Jobs'
@deck.add_intro title, subtitle

# Creating a text-only slide:
# Title must be a string.
# Content must be an array of strings that will be displayed as bullet items.
title = 'Why Mac?'
content = ['Its cool!', 'Its light.']
@deck.add_textual_slide title, content

# Creating an image Slide:
# It will contain a title as string.
# and an embeded image
title = 'Everyone loves Macs:'
image_path = 'samples/images/sample_gif.gif'
@deck.add_pictorial_slide title, image_path

# Specifying coordinates and image size for an embeded image.
# x and y values define the position of the image on the slide.
# cx and cy define the width and height of the image.
# x, y, cx, cy are in points. Each pixel is 12700 points.
# coordinates parameter is optional.
coords = {x: 124200, y: 3356451, cx: 2895600, cy: 1013460}
@deck.add_pictorial_slide title, image_path, coords

# Saving the pptx file to the current directory.
@deck.save('test.pptx')

4

http://tomasvarsavsky.com/2009/04/04/simple-word-document-templating-using-ruby-and-xml/

如果您能够创建模板并填充值,请考虑这种方法。

Office Open XML文件格式

新的Office文件格式(.docx、.xlsx、.pptx文件)基本上是一组压缩的XML文件。我们专注于Word文件(.docx),但这种方法也适用于其他类型的文件。该格式的规范有几千页。如果没有专门处理格式所有细节的库,从头开始生成文件将是一项相当困难的任务。因此,我们在Word中起草了模板,并放置了标记来告诉我们的模板引擎要插入值的位置。我们创建了文档属性,这些属性参考数据值,并将其作为字段添加到文档中,以插入值的位置。例如,我们可以有像这样的字段:

label_tag #{data[:user].name}
label_tag #{data[:user].address}
label_tag #{data[:booking].number}
label_tag #{data[:booking].items.collect{|i| i.name}.join(‘,’)}

否则,曾经有一次尝试(三年前上传的WIP,我不指望它会完成,但应该有助于创建幻灯片的方法)创建PowerPoint幻灯片。以下是代码示例。 https://github.com/jpoz/rubypoint/blob/master/lib/rubypoint/presentation.rb
def new_slide
  RubyPoint::Slide.new(self)
end

谢谢!我今晚会研究一下这个! - MalSu
这是完美的指导,我接受它作为答案,谢谢! - MalSu
你找到解决办法了吗?我有类似的问题。 - Joelio
@Joelio 我最终确实建立了一个基本的 PPT,但是在我深入研究之前,需求就发生了变化。 - MalSu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接