A ruby library for generating word documents that can handle basic html and images too.
Add this line to your application's Gemfile:
gem 'open_xml'
And then execute:
$ bundle
Or install it yourself as:
$ gem install open_xml
Provide a path to a docx with the text [SUPERPOWER] placed anywhere.
require 'open_xml'
doc = OpenXml::TemplateDocument.new(path: "[path to template]")
doc.process({"[SUPERPOWER]" => {text: "Bug Fixing!!!!"}})
IO.write "./powers.docx", doc.to_zip_buffer.string
HTML content
doc = OpenXml::TemplateDocument.new(path: "[path to template]")
doc.process({"[SUPERPOWER]" => {text: "<h1>Bug Fixing!!!!</h1>", html: true}})
HTML with images
doc = OpenXml::TemplateDocument.new(path: "[path to template]")
doc.process({"[SUPERPOWER]" => {text: "<img src='/powers.png' />", html: true, images: {'/powers.png' => "[Base64 encoded image]"}}})
Implement reading and writing the word zip filesCreate a template word document with formatted key words (bold, 14pt).Replace the key words with the supplied plain text content but maintain all the formatting.Handle replacing a key with multiple contentExtract these features into a gemFormat html content for wordprocessingML e.x. bold, italic, underline and handle images
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request