我处于这样一种情况,必须通过编程构建PowerPoint演示文稿,并通过Web应用程序提供生成的ppt文件,最好使用Rails、JavaScript或Ruby。这是否可行?如果可以,如何以及使用哪些工具?
我对如何最好地解决这个问题的任何建议都持开放态度。谢谢!
我处于这样一种情况,必须通过编程构建PowerPoint演示文稿,并通过Web应用程序提供生成的ppt文件,最好使用Rails、JavaScript或Ruby。这是否可行?如果可以,如何以及使用哪些工具?
我对如何最好地解决这个问题的任何建议都持开放态度。谢谢!
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')
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(‘,’)}
def new_slide
RubyPoint::Slide.new(self)
end