Difference between revisions of "Creating OpenOffice templates"
(→Data format) |
|||
(13 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
In order to make a relation between the template form field and the property group, you have to name them following a naming convention: replace ":" and "." by "_". Here you can see the matching between both fields: | In order to make a relation between the template form field and the property group, you have to name them following a naming convention: replace ":" and "." by "_". Here you can see the matching between both fields: | ||
+ | |||
{| align="center" border="0" cellpadding="5" cellspacing="0" style="width: 600px" | {| align="center" border="0" cellpadding="5" cellspacing="0" style="width: 600px" | ||
− | ! align="left"| PROPERTY GROUP NAME !! align="left"| TEMPLATE FIELD NAME | + | ! align="left"| PROPERTY GROUP NAME !! align="left"| TEMPLATE FIELD NAME || TEMPLATE FIELD VALUE |
|- | |- | ||
− | |okp:tpl.name || okp_tpl_name | + | |okp:tpl.name || okp_tpl_name || ${okp_tpl_name!} |
|- | |- | ||
− | |okp:tpl.bird_date || okp_tpl_bird_date | + | |okp:tpl.bird_date || okp_tpl_bird_date || ${okp_tpl_bird_date!} |
|- | |- | ||
− | |okp:tpl.language || okp_tpl_language | + | |okp:tpl.language || okp_tpl_language || ${okp_tpl_language!} |
|- | |- | ||
|} | |} | ||
+ | |||
To create a template in OpenOffice.org go to '''View''' > '''Toolbars''' > '''Form Controls'''. The a new dialog will appear and you will be able to add form elements to the document. This dialog contains form stuff such as Labels, Text Boxes, Check Boxes, etc. | To create a template in OpenOffice.org go to '''View''' > '''Toolbars''' > '''Form Controls'''. The a new dialog will appear and you will be able to add form elements to the document. This dialog contains form stuff such as Labels, Text Boxes, Check Boxes, etc. | ||
Line 22: | Line 24: | ||
Hi ${name}! | Hi ${name}! | ||
− | However, mixing processing instructions and normal text into the document may become confusing and clutter the layout. So JODReports provides an alternative way of inserting fields. You can insert a visual field in OpenOffice.org Writer from the menu Insert / Fields / Other... (or just press Ctrl+F2), then click on the Functions tab and select Input field. Change the field Reference to '''JOOScript''' and in the following field Content enter the variable name (e.g. "$name"). This field will typically be displayed by Writer as a grayed rectangle with the variable name, while moving the mouse over it will reveal the field reference. | + | However, mixing processing instructions and normal text into the document may become confusing and clutter the layout. So JODReports provides an alternative way of inserting fields. You can insert a visual field in OpenOffice.org Writer from the menu '''Insert''' / '''Fields''' / '''Other...''' (or just press '''Ctrl+F2'''), then click on the '''Functions tab''' and select '''Input field'''. Change the field Reference to '''JOOScript''' and in the following field Content enter the variable name (e.g. "$name"). This field will typically be displayed by Writer as a grayed rectangle with the variable name, while moving the mouse over it will reveal the field reference. |
− | This is the OpenOffice.org document in this sample: [[File:Tpl.odt]]. | + | This is the OpenOffice.org document used in this sample: [[File:Tpl.odt]]. |
Read about OpenOffice.org templates at [http://jodreports.sourceforge.net/ JODReports]. | Read about OpenOffice.org templates at [http://jodreports.sourceforge.net/ JODReports]. | ||
+ | |||
+ | == Data format == | ||
+ | JODReports uses FreeMarker inside, so you can take advantage of the FreeMarker formatting flexibilities. For example you can set date format by this way: | ||
+ | |||
+ | ${okp_tpl_bird_date?string("yyyy-MM-dd")} | ||
+ | |||
+ | If date may be null, then you need to check this: | ||
+ | |||
+ | <#if okp_tpl_bird_date??>${okp_tpl_bird_date?string("yyyy-MM-dd")}</#if> | ||
+ | |||
+ | Learn more about FreeMarker formatting at [http://freemarker.sourceforge.net/docs/ref_builtins.html Built-in Reference]. | ||
+ | |||
+ | == Dynamic tables == | ||
+ | You can even use the template feature to generate dynamic tables. Lets see an example. | ||
+ | |||
+ | |||
+ | <center>[[File:Openoffice templates 002.png|542px]]</center> | ||
+ | |||
+ | |||
+ | In the screenshot you can see an document with a table. The header has a colored background and also is bold. The script show is user to generate the table headers. | ||
+ | |||
+ | This is the OpenOffice.org document used in this sample: [[File:Dynamic table.odt]]. | ||
+ | |||
+ | Learn more about this feature at: | ||
+ | * [http://jodreports.sourceforge.net/?q=node/26 JODReports: Inserting Directives at Special Locations]. | ||
+ | * [http://sourceforge.net/apps/phpbb/jodreports/viewtopic.php?f=2&t=42 Dynamic table column count] | ||
[[Category: Installation Guide]] | [[Category: Installation Guide]] | ||
− |
Latest revision as of 11:39, 15 January 2014
In order to make a relation between the template form field and the property group, you have to name them following a naming convention: replace ":" and "." by "_". Here you can see the matching between both fields:
PROPERTY GROUP NAME | TEMPLATE FIELD NAME | TEMPLATE FIELD VALUE |
---|---|---|
okp:tpl.name | okp_tpl_name | ${okp_tpl_name!} |
okp:tpl.bird_date | okp_tpl_bird_date | ${okp_tpl_bird_date!} |
okp:tpl.language | okp_tpl_language | ${okp_tpl_language!} |
To create a template in OpenOffice.org go to View > Toolbars > Form Controls. The a new dialog will appear and you will be able to add form elements to the document. This dialog contains form stuff such as Labels, Text Boxes, Check Boxes, etc.
A field that will be replaced with the value of a variable passed can be specified using the standard FreeMarker expression notation by typing the variable name into the document as follows:
Hi ${name}!
However, mixing processing instructions and normal text into the document may become confusing and clutter the layout. So JODReports provides an alternative way of inserting fields. You can insert a visual field in OpenOffice.org Writer from the menu Insert / Fields / Other... (or just press Ctrl+F2), then click on the Functions tab and select Input field. Change the field Reference to JOOScript and in the following field Content enter the variable name (e.g. "$name"). This field will typically be displayed by Writer as a grayed rectangle with the variable name, while moving the mouse over it will reveal the field reference.
This is the OpenOffice.org document used in this sample: File:Tpl.odt.
Read about OpenOffice.org templates at JODReports.
Data format
JODReports uses FreeMarker inside, so you can take advantage of the FreeMarker formatting flexibilities. For example you can set date format by this way:
${okp_tpl_bird_date?string("yyyy-MM-dd")}
If date may be null, then you need to check this:
<#if okp_tpl_bird_date??>${okp_tpl_bird_date?string("yyyy-MM-dd")}</#if>
Learn more about FreeMarker formatting at Built-in Reference.
Dynamic tables
You can even use the template feature to generate dynamic tables. Lets see an example.
In the screenshot you can see an document with a table. The header has a colored background and also is bold. The script show is user to generate the table headers.
This is the OpenOffice.org document used in this sample: File:Dynamic table.odt.
Learn more about this feature at: