Help:Word format

The result format word is used to format query results as a word file.

If the PHPWord library (required) is installed this format will automatically be available (SRF ≥ 1.9.1).

Parameters

 * templatefile - the name of a docx word file containing ${needle} placeholders. It is automatically searched for in the File: namespace.

Example
We'd like to get a table of cities that have a population of more than 1 million people sorted by population


 * Same query for Word format

Preparing a Template File
The Template file needs to have  placeholders where the field results are to be inserted, e.g.   would hold the population result.

Caveats
Unfortunately when saving Microsoft Word files extra characters might get inserted see:

See this issue on stackoverflow.com

To avoid this you might want to
 * switch off correction mode (which might add red markups)
 * use cut&paste in a formatless mode

You might want to check that the needles $ { … } where not spoiled in the resulting Docx xml format. You can check this by unzipping the docx file and looking into the word/document.xml file.

A Tool like xmlstarlet can help with doing this.

Here is a few lines of bash script as an example The result should look like: ${population} …

As a script "caveat" this looks like:

Installation
This describes how to install the required PHPWord library with Composer, which is recommended method for MW 1.22+. Either enter the following in you command line:

or add the following as the last line of the "require" section in your "composer.json" file:

Replace the version number "dev-master" of this example with the version number you want to install at your convenience.

Patching TemplateProcessor.php for Image handling
If you'd like to insert Images into your word file you might want to patch the TemplateProcessor.php file of PhpOffice/PhpWord like this: see
 * http://stackoverflow.com/questions/24018003/how-to-add-set-images-on-phpoffice-phpword-template

The SRF_Word format will automatically detect that the method searchImageId is available and will use it.