xv1t/opendocument-template 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

xv1t/opendocument-template

Composer 安装命令:

composer require xv1t/opendocument-template

包简介

Rendering templates with multidimensional data into a reports

README 文档

README

Project name OpenDocumentTemplate
Language PHP
Source files ODS, ODT

#Fast generation OpenDocument reports Support files: ODS, ODT

Template Report
Bill document template (ODS) See the great manual /examples/documents
Simple cards with data (ODS) /examples/continents
Dynamic pictures (ODS) /examples/pictures
15 level deep dimensions (ODS) /examples/deepdata

Recommended software for create template

  • LibreOffice
  • OpenOffice

Your done report files was correct opened in

  • LibreOffice
  • OpenOffice
  • MS Office >=2010

Fast manual (ods)

  1. Create template ods file
  2. Put elements
  3. Mark ranges
  4. Load data from database
  5. Render data through template file info your new ods file
  6. 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:

[] A B C
1 [Report.name] [Report.date] [Report.author]
2
3

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:

[] A B C
1 Test Report 2016-09-25 Me
2
3

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

[] A B C D E
1 [Report.name] Author [Report.author]
2 Cities
3 City [City.name]
4 Streets [City.streets]
5 Population [City.population]
6 Mayor [Mayor.name]
7 Squares
8 name length width
9 [Square.name] [Square.length] [Square.width]
11 Squares count [COUNT(Squares)]
12 Cities count [COUNT(Cities)]
13 Report date [Report.date]

Well, we have a 3 level dimension array of objects:

In LibreOffice Calc they are called Range names.

Insert -> Names => Manage

Examples

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固