User's Guide > About the User's Guide > Word and Excel Templates > Excel Templates > Advanced Script Tags and Groovy and Velocity Scripts
Advanced Script Tags and Groovy and Velocity Scripts
While simple property acesss and JEXL expressions are sufficient in most cases, sometimes you may need some more powerful script or template for building the export data.
For these cases the Excel export contains few tags that can execute a Groovy or Velocity scripts.
These tags are available:
Tag Name
Description
cb:script
Executes a template using the default script language -Velocity- and puts result to cell.
cb:groovy
Evaluates a Groovy template, and puts result to cell.
cb:velocity
Executes a velocity template and puts result to cell.
For example this tag:
<cb:groovy>Groovy name:${item.name}</cb:groovy>
Will set the cell to if the exported item's name is "my bug"
Groovy name:my bug
Another example for using a Regexp from Groovy to extract some data:
<cb:groovy template="false" silent="false"> email = item.submitter.email; domainRegexp = /@(.*?)\./; matcher= (email =~ domainRegexp); return matcher[0][1];</cb:groovy>
This will extract domain name from the email address of the issues. For example, if the submitter is zluspai@intland.com the script will put the intland text to the cell.
* 
Limitations of scripts:
The cb:script tags will use the complete content of the 1st cell as script, even that part which is outside of the <cb:script>...</cb:script> tags!
These tags will ignore and remove all the remaining cells even that the tag spans multiple cells
The cb:groovy tag has some special feature that it can run in two different modes: as template or as script. The template mode means that the script is evaluated as a Groovy Simple Template , which has following main characteristics:
The template is producing a string output (not a date or number).
Bean properties are accessed using the ${bean.property} notation.
The new variables declared inside the template are local, which means they are lost when the template evaluation is completed.
An example of this:
<cb:groovy>Hello ${world}</cb:groovy>
On the other hand, the Groovy template can run in script mode. That mean that the script-text is evaluated as some Groovy code. For example:
<cb:groovy template="false" silent="false">item.submittedAt</cb:groovy>
This differs from the template mode as:
The variables and bean properties are accessed using the simple dot (bean.property) notation, no ${...} text is needed around.
Any variables declared in the script will be available later as beans in the scope. For example:
<cb:groovy template="false">email = item.submitter.email</cb:groovy>

will create an email bean in the scope which later can be used as ${email} elsewhere in the Excel document.
By default the script won't produce any output, which means it won't write anything to cell. However if the silent=false property is set then return value of the script will be inserted to the table cell. This means that it can return date objects or numbers too, like in this example the cell will contain a date data.
Was this helpful?