Pretty simple gem to deal with flat xml templates for OpenOffice. It allows you to substitute any marked words on the page and even data table values for charts.
If we have template (template.fodp for example) that contain following text on the one of it’s slides
BasicObject is the __parent__ class of all classes in Ruby. It’s an explicit blank class.
Here ‘__parent__’ is the marker. Then you can substitute this arker with any other text like this:
+ presentation = OOffice::Presentation IO.read ‘path to template.fodp’ presentation.parent = ‘parent since ruby 1.9’ +
and then presentation.to_xml will contain:
BasicObject is the parent since ruby 1.9 class of all classes in Ruby. It’s an explicit blank class.
Consider our template contains a number of charts. Each chart in presentation has it’s own data table and it’s data can be changed with this lib.
To mark chart for substitution just right click over chart and select “name” to change chart name. Assign new name to chart like table::sex_and_age_chart
. Name must contain mandatory key word (table
) and some another name by you (to access it via substitution api) joined with ::
.
Now wi can change data it table like: + presentation = OOffice::Presentation IO.read ‘path to template.fodp’ presentation.tables.sex_and_age_chart(:rows => [[1, 20], [2, 30], [3, 40]]) + or + presentation.tables.sex_and_age_chart(:coluns => [[1, 2, 3], [20, 30, 40]]) +
To get the result of substitution just call presentation.to_xml
and write it into the file.
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright © 2010 saksmlz. See LICENSE for details.