Reports? Docx the Solution!
Join the DZone community and get the full member experience.Join For Free
reports creation is a common problem to face with, when developing web applications. when designing a report, usually a tool is needed to define the report content and the usage of such tools is not always easy and intuitive. consequently, specific skills and expertise are required in order to use these products.
the same problem arose also with a rapid application development tool like 4ws.platform, a product designed specifically to speed up and make it easier the creation of web and mobile applications, having an high level of customization and allowing the creation of applications to users having basic skills.
which solution can be provided to users in order to make it easy and fast the creation of reports within 4ws.platform? how to do that in a similar simple way already available in that product for other tasks?
word processors like microsoft word™  , open office o libre office are widespread solutions whose usage is easy and well known by a large amount of users. people know how to use them, for instance to write a letter, compile a bill, an essay or to create a resume, etc.
why don't exploit the knowledge of these editors that everyone has and start from that?
these editors procude documents in a docx format, which is based on an xml descriptor easily readable by 4ws.platform.
the widespread of these tools, the semplicity in the creation of documents and the chance to exploit the xml format behind the scenes easily readable are the main reasons for the adoption of the docx format to use for the document template within 4ws.platform for the reports generation.
in this way, any user can create document templates using these popular editors, format and organize data as they wish and follow simple rules to create a model to populate and finally publish them inside 4ws.platform to generate reports.
how to create a docx template
as described in the introduction, a user can create his own template by following a few simple rules, but first of all, he can fill in the template, format the content, define the content layout and focus mainly on the result he wants to reach.
once defined the “static” content and layout of the template, the user has to focus on the “dynamic” parts of the document, which will be replaced with data provided by the application, when generating the report starting from the template.
finally, when the template has been deployed within 4ws.platform, queries have to be defined to feed the report for those parts.
two kinds of variables written in the docx template are supported by 4ws.platform. these variables have the following syntax:
the value will be replaced with data retrieved through the execution of the query linked to that part of the template
the description will be replaced with data coming from the query execution and translated according to the language used when generating to the report.
the result is reported in the following images.
in addition to what just described, two types of subreports are supported by 4ws.platform:
- a ‘table subreport’ used to show a list of records
- a ‘form subreport’, used to show values coming for a single report.
these two subreports have the following syntax:
where ‘table’ is the name assigned to the ‘table subreport’, in order to identify it and, for each column of that subreport, an identifier having this syntax:<td>column1</td> <td>column2</td> …it is always possible to include cells whose content is translated according to the report language, using the tag: ‘tdtranslation‘.
all cells having <td> tag will be replicated for each record read through the execution of query linked to that subreport.
here it is an example of the result of such a kind of subreport.
where subform is the name assigned to the subreport and whose controls are identified by ‘subcontrol’ tags or ‘subcontroltranslation’ tags, in case of data to translate according to the report language.
how to feed the template
once the user has defined the template, a query has to be written to provide data to show in the report and for each subreport.
4ws.platform provides several ways to define those queries, through what is called a ‘business component’: the user can define the sql query manually or use the automatic query composition provided by the 4ws.platform feature.
how to configure a report
when the user has defined the template and the queries to feed it, the next step is to configure the report within the “web designer” component of 4ws.platform.
in order to complete the template configuration and make it possible to generate a report, 4 simple steps are needed:
1. uploading the template
the first step includes the name specification for the report and the selection of a business component to link to the report in order to fill in the main section of the report.
through this feature, the user can choose the docx template file to upload: it is possible to upload a different file for each language, with the constraint that each of these templates have to share the same structure, so that it is possible to fill in each of them with the same data structure.
the report content could depend on data passed in input to that report. that means that the single sql query could have variables which should be filled with dynamic data. for each of these variables a parameter can be defined along with the other settings provided when defining the report. these parameters have a data type which can be: text, number or date. they can be used when mapping sql query variables with ad hoc data.
3. report fields
once uploaded the docx template, the file is analyzed and a grid is prompted to the user, showing the fields found inside the template that require a mapping, that is to say, to map to the query fields, in order to fill them in.
for each of these bindings, it is possible to define a predefined data format (text, date, integer, decimal, etc.) or take advantage of advanced formatting methods provided by 4ws.platform.
in the screenshot reported below, a function named ‘formatnumber’ is used to manage the number format, but it is also available a special function to convert a number to its text representation, expressed in a specific language.
in case the uploaded docx template contained subreports (table or form subreports type), a second grid would show the list of these subreports. through that grid, the user can bind each subreport with a business component (a sql query) to use to feed that subreport.
moreover, for each subreport the mapping between its fields and the query fields must be defined by the user, in the same way done for the main region of the report.
a user can change any part of these report settings any number of times: he can change format settings, mappings or change the template content (e.g. static content) by simply uploading the docx file again.
when the user has completed the report settings, the template could be invoked in order to generate a report starting from it and data coming from the execution of the sql queries.
a report can be generated by invoking it through a server-side action.
in the simplest case, such an action would simply contain a line of code to generate the report, starting from the docx file location:
utils.generatedocx(reportid, args, langid, path, filename);
once the report has been generated (in docx format), it is also possible to convert it in another format, for instance a report in pdf format.
to sum up, a report can be produced on the fly without the need to know how to use ad hoc report editors or pay for costly licenses. you can create report templates in docx format with a simple word processor and through 4ws.platform automate the report generation.
thanks to popular text editors able to manage docx file format, any newbie user can create report templates and with the simple and intuitive web interface included in the 4ws.platform solution anyone can also be able to configure and manage the report generation.
 microsoft, encarta, msn, and windows are either registered trademarks or trademarks of microsoft corporation in the united states and/or other countries.
Opinions expressed by DZone contributors are their own.