Skip to content

bagilevi/docx_builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DocX Builder

DocX Builder is a small utility to help you compose a docx (Microsoft Word 2007) based on a template’s XML.

The slice_template.rb can be used separately for non-docx applications.

The steps:

  1. Create a docx file with Microsoft Word or OpenOffice.org
  2. Unzip it (the docx file is actually a ZIP package)
  3. Create your template from word/document.xml
  4. Open the template and reformat it (I used RubyMine)
  5. Find the parts you need to generate programmatically, and mark them up with … , see example/plan_report_template.xml
  6. Remove the formatting (compact the XML)
  7. Create your builder, see example.rb

The example explained

  _____head______ _________area_______________________________________ _foot_
 |               |                                                    |      |
 |               |                ________goal________________________|      |
 |               |               |                                    |      |
 |               |               |                _______objective____|      |
 |               |               |               |                    |      |
 |  (Plan Name)  |  (Area Name)  |  (Goal Name)  |  (Objective Name)  |      |
 _____________________________________________________________________________
                                  XML DOCUMENT

You can assign a text to a placeholder:

 template['head']['Plan Name'] = @plan.name

Or you can replace a slice with a string, that can be composed by multiplying that slice:

  template['area'] =
    @plan.areas.map do |area|

      area_slice = template['area'].clone
      area_slice['Area Name'] = area.description
      area_slice['goal'] = '...'
  end

See example.rb

About

Compose docx file (Microsoft Word 2007) based on a template XML

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages