PHP code example of xv1t / opendocument-template

1. Go to this page and download the library: Download xv1t/opendocument-template library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xv1t / opendocument-template example snippets



eate object

$template = new OpenDocumentTemplate();


$data = array(
    'Report' => array(
        'name' => 'Test Report',
        'date' => '2016-09-25',
        'author' => 'Me'
    )
);


$template->open('sample_report.ods', 'sample_report-out.ods', $data)


$data = array(
    'Report' => array(/* main Report data */),
    'Cities' => array(
        array(/* city data */),
        array(/* city data */),
        array(/* city data */),
        array(/* city data */),
    )
);



//Sample of one City object
array(
    'City' => array(
        'name' => 'Albatros',
        'streets' => 165,
        'population' => 1300000
    )
);

$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
            )
        ),
    )
);



$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
            ),
        ),
    )
);


$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(/*...*/),
            )
        ),
       
    )
);


array(
    'Sqaure' => array(
        'name' => 'Trafalgaar',
        'length' => 23,
        'width' => 45
    )
)



$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
                    )
                ),
            )
        ),
    )
);