xv1t / opendocument-template
Rendering templates with multidimensional data into a reports
This package is not auto-updated.
Last update: 2024-12-11 21:34:28 UTC
README
#Fast generation OpenDocument reports
Support files: ODS
, ODT
Recommended software for create template
- LibreOffice
- OpenOffice
Your done report files was correct opened in
- LibreOffice
- OpenOffice
- MS Office >=2010
Fast manual (ods)
- Create template ods file
- Put elements
- Mark ranges
- Load data from database
- Render data through template file info your new ods file
- Open in the LibreOffice Calc or other and enjoy
Requirements
Php extensions
- zip
- xml
Php version >=5.3
Recommended sowfware for templating: LibreOffice 5
Install
Put file OpenDocumentTemplate.php
into your project, and use it
<?php include_once "OpenDocumentTemplate.php"; //create object $template = new OpenDocumentTemplate();
First simple report
Prepare your data
Data - is array in php. Recommend all object fields group in object name.
<?php $data = array( 'Report' => array( 'name' => 'Test Report', 'date' => '2016-09-25', 'author' => 'Me' ) );
All fields grouping in the Report
parent array.
This method of naming provides a powerful technique for multidimensional data.
Design template file
Open the LibreOffice Calc. Create new spreedsheet;
add a 3 cells for next contents:
Save it with name sample_report.ods
.
Render template with data
<?php $template->open('sample_report.ods', 'sample_report-out.ods', $data)
And open new file sample_report-out.ods
and you see in sheet:
Add second dimension
Add a key Cities
for the list of objects
<?php $data = array( 'Report' => array(/* main Report data */), 'Cities' => array( array(/* city data */), array(/* city data */), array(/* city data */), array(/* city data */), ) );
All Cities
object must be have an identical list of the fields. In our example: name
, streets
, population
<?php //Sample of one City object array( 'City' => array( 'name' => 'Albatros', 'streets' => 165, 'population' => 1300000 ) );
And all data
$data = array( 'Report' => array( 'name' => 'Test Report', 'date' => '2016-09-25', 'author' => 'Me' ), 'Cities' => array( array( //first object 'City' => array( 'name' => 'Albatros', 'streets' => 165, 'population' => 1300000 ) ), array( //next object 'City' => array( 'name' => 'Turtuga', 'streets' => 132, 'population' => 750000 ) ), array( //next object 'City' => array( 'name' => 'Palmtown', 'streets' => 18, 'population' => 10000 ) ), ) );
Add a other object as linear dimesion
Add inforamation about the mayor of the each city, in the sibling key Mayor
<?php $data = array( 'Report' => array(/*...*/), 'Cities' => array( array( 'City' => array(/*...*/), 'Mayor' => array( 'name' => 'John Do', 'old' => 47 ), ), array( 'City' => array(/*...*/), 'Mayor' => array( 'name' => 'Mary Ann', 'old' => 32 ), ), array( 'City' => array(/*...*/), 'Mayor' => array( 'name' => 'Mike Tee', 'old' => 29 ), ), ) );
Add third dimesions
Add a key Squares
for the list of the squares in the each city
<?php $data = array( 'Report' => array(/*...*/), 'Cities' => array( array( 'City' => array(/*...*/), 'Mayor' => array(/*...*/), 'Squares' => array( array(/*...*/), array(/*...*/), array(/*...*/), ) ), array( 'City' => array(/*...*/), 'Mayor' => array(/*...*/), 'Squares' => array( array(/*...*/), array(/*...*/), array(/*...*/), array(/*...*/), array(/*...*/), ) ), array( 'City' => array(/*...*/), 'Mayor' => array(/*...*/), 'Squares' => array( array(/*...*/), array(/*...*/), ) ), ) );
Example Square object:
<?php array( 'Sqaure' => array( 'name' => 'Trafalgaar', 'length' => 23, 'width' => 45 ) )
And out $data
finish version:
<?php $data = array( //level1 'Report' => array( 'name' => 'Test Report', 'date' => '2016-09-25', 'author' => 'Me' ), 'Cities' => array( array( //level 2 'City' => array( 'name' => 'Albatros', 'streets' => 165, 'population' => 1300000 ) 'Mayor' => array( 'name' => 'John Do', 'old' => 47 ), 'Squares' => array( array( //level 3 'Sqaure' => array( 'name' => 'Trafalgaar', 'length' => 23, 'width' => 45 ) ), array( 'Sqaure' => array( 'name' => 'Square #2', 'length' => 23, 'width' => 45 ) ), array( 'Sqaure' => array( 'name' => 'Square #3', 'length' => 23, 'width' => 45 ) ), ) ), array( 'City' => array( 'name' => 'Turtuga', 'streets' => 132, 'population' => 750000 ) 'Mayor' => array( 'name' => 'Mary Ann', 'old' => 32 ), 'Squares' => array( array( 'Sqaure' => array( 'name' => 'Square #4', 'length' => 23, 'width' => 45 ) ), array( 'Sqaure' => array( 'name' => 'Square #5', 'length' => 23, 'width' => 45 ) ), ) ), array( 'City' => array( 'name' => 'Palmtown', 'streets' => 18, 'population' => 10000 ), 'Mayor' => array( 'name' => 'Mike Tee', 'old' => 29 ), 'Squares' => array( array( 'Sqaure' => array( 'name' => 'Square #6', 'length' => 23, 'width' => 45 ) ), array( 'Sqaure' => array( 'name' => 'Square #7', 'length' => 23, 'width' => 45 ) ), array( 'Sqaure' => array( 'name' => 'Square #8', 'length' => 23, 'width' => 45 ) ), ) ), ) );
Design a spreedsheet
Well, we have a 3 level dimension array of objects:
In LibreOffice Calc they are called Range names
.
Insert
-> Names
=> Manage