Command Reference CIB jsMerge

Example

The following describes a complete, short example of a CIB jsMerge run. The files used are printed in their entirety.

Starting point is the root document inputDoc.odt. Data is merged from a CSV file (Persons.csv) and additionally the template template.odt is included.

CIB jsMerge is called via CIB runshell on command line in this example. The properties are specified in the script file script.js:

Call:
Cibrsh.exe –js scriptfile=script.js

script.js:

Only the required properties for this example are specified in this script file. In this case, that is license information, name of the root document, name od the output file and name of the CSV file.

setProperty("licenseCompany", "Licensee", true);
setProperty("licenseKey", "xxxx-xxxxx-xxxxxxxx", true);
setProperty("inputfile", "./inputDoc.odt", true);
setProperty("outputfile", "./outputDoc.odt", true);
setProperty("datafile", "Persons.csv", true);

inputDoc.odt:

At the start of the root document the local function "upperCase" is defined. It is later called inside a "while" loop to print the names, included from "Persons.csv" in the third table column, in upper case. The next field instruction merges the current date to the result document via the function "formatDate()". Then the additional template "template.odt" is included via the field instruction "include()". The following construct dynamically creates a table using a "while" loop and fills it with the data from the data supply "Persons.csv". As many table rows are created as there are entries(records) in the file "Persons.csv". This is realized using the functions "hasRec()" and "nextRec()".

The first table column in the root document shows the usage of a "if" condition to choose the right salutation. The second column demonstrates the display of the "Persons" variable's value via the "fref()" function, while in the third column the value of the variable "lastname" is passed to the function "upperCase".

The document inputDoc.odt is printed on the following page.


inputDoc.odt

{ # this.upperCase = function(name) { text(name.toUpperCase());} }

 

Output of the current date:

Munich, the { #text(formatDate(„tt.MM.jj“, new Date() )) }

 

Include text from an additional template:

{ # include("template.odt") }

 

The following table is created dynamically via a while loop. Data from the CSV file Persons.csv are used and as many table rows created as there are records in the CSV file.

{ #while(hasRec(„Persons“)){ 'x

{#if(ref(„gender“)==“m“) { 'Mr } else{ 'Mrs } }

{ #fref(„firstname“) }

{ # this.upperCase (ref(„lastname“)) }

{ #nextRec(„Persons“) } } }


 

template.odt:

The content of the file "template.odt" is included in the root document at the position specified using the "include()" statement:

This is a text notice, defined in the template "template.odt" and included into the output file via the "include()" statement.


Persons.csv

This file is the data supply. In the first row the variable names are defined, the following rows contain the corresponding records.

Note:
The CSV file has to be UTF-8 encoded to correctly process special characters and Umlauts.

firstname;lastname;gender
Peter;Meier;m
Hans;Müller;m
Anne;Kurz;f Tim; Berg;m


outputDoc.odt:

After calling CIB jsMerge the document printed on the next page is created. All the data has been merged into this document as described above.


 

outputDoc.odt

Output of the current date:

Munich, the 01.09.14

 

Include text from an additional template:

This is a text notice, defined in the template "template.odt" and included into the output file via the "include()" statement.


The following table is created dynamically via a while loop. Data from the CSV file Persons.csv are used and as many table rows created as there are records in the CSV file.

Mr

Peter

MEIER

 

Mr

Hans

MÜLLER

 

Mrs

Anne

KURZ

 

Mr

Tim

BERG