Project

open_xml

0.01
No commit activity in last 3 years
No release in over 3 years
Generate Word documents from a template, also handle html and images too.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0

Runtime

~> 1.6
~> 1.1
 Project Readme

OpenXml

A ruby library for generating word documents that can handle basic html and images too.

Installation

Add this line to your application's Gemfile:

gem 'open_xml'

And then execute:

$ bundle

Or install it yourself as:

$ gem install open_xml

Usage

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]"}}})

Todo

  • Implement reading and writing the word zip files
  • Create 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 content
  • Extract these features into a gem
  • Format html content for wordprocessingML e.x. bold, italic, underline and handle images

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request