使用Rails创建powerpoint演示文稿

Mal*_*lSu 5 javascript ruby powerpoint ruby-on-rails web

我需要以编程方式构建PowerPoint演示文稿并通过Web应用程序提供最终的ppt文件,最好使用Rails,JavaScript或Ruby.这可能吗?如果是这样,如何以及使用哪些工具?

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

Gre*_*ean 6

这种红宝石宝石似乎比目前接受的答案中提到的更为成熟.

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')
Run Code Online (Sandbox Code Playgroud)


Hit*_*eeb 4

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

\n

如果您可以创建模板并填充值,请考虑此方法。

\n
\n

Office Open XML 文件格式

\n

新的 Office 文件格式(.docx、.xlsx、.pptx 文件)基本上是 XML 文件的压缩集合。我们专注于 Word 文件\n(.docx),但此方法也适用于任何其他类型的\n文件。该格式的规范有数千页。在没有专门构建的库来处理格式的所有复杂性的情况下从头开始生成文件将是一项相当艰巨的任务。相反,我们在 Word 中起草了模板并放置了标记\n以告诉我们的模板引擎在何处插入值。我们创建了引用数据值的文档属性,并将这些属性作为字段添加到文档中应插入值的位置。例如,我们可以有这样的字段:

\n
\n
label_tag #{data[:user].name}\nlabel_tag #{data[:user].address}\nlabel_tag #{data[:booking].number}\nlabel_tag #{data[:booking].items.collect{|i| i.name}.join(\xe2\x80\x98,\xe2\x80\x99)}\n
Run Code Online (Sandbox Code Playgroud)\n

否则,曾尝试过创建 PowerPoint 幻灯片(三年前上传的 WIP,我不希望它完成,但应该有利于创建创建幻灯片的方法)。这是代码示例

\n

https://github.com/jpoz/rubypoint/blob/master/lib/rubypoint/presentation.rb

\n
def new_slide\n  RubyPoint::Slide.new(self)\nend\n
Run Code Online (Sandbox Code Playgroud)\n