vernes / PHPReport

Library for generating reports from PHP
71 stars 50 forks source link

How to export to excel with template #5

Closed dukec2020 closed 11 years ago

dukec2020 commented 11 years ago

The attach file describe data, there are multi category and each category has many issue. How to make template and setup data for this situation.

screen shot 2013-07-31 at 11 37 36 pm

vernes commented 11 years ago

Hi You may generate rows multiple times. First time you generate more {tags} for second time. Make template simple, one row for category, one for issues. You then load data for categories and generate all categories and for each category one row for issues to repeat. And then you load data for issues and generate rows for each category.

So:

$R=new PHPReport(...template...);
$R->load(...categories array...)
$R->generateReport()
...
$R->load(...issues array...)
$R->generateReport()
...
$R->renderXlsx(...)

I hope this helps.

dukec2020 commented 11 years ago

I'll try it now. Thanks! On Aug 1, 2013 3:53 AM, "vernes" notifications@github.com wrote:

Hi You may generate rows multiple times. First time you generate more {tags} for second time. Make template simple, one row for category, one for issues. You then load data for categories and generate all categories and for each category one row for issues to repeat. And then you load data for issues and generate rows for each category.

So:

$R=new PHPReport(...template...);$R->load(...categories array...)$R->generateReport()...$R->load(...issues array...)$R->generateReport()...$R->renderXlsx(...)

I hope this helps.

— Reply to this email directly or view it on GitHubhttps://github.com/vernes/PHPReport/issues/5#issuecomment-21894826 .

dukec2020 commented 11 years ago

Here is my code:

$r = new PHPReport(.. template...)
            $r->load ( array (
                    array (
                            'id' => 'c',
                            'data' => array (
//                                  'name' => 'category 1'
                                    array('name' => 'category 1' ) ,
                                    array('name' => 'category 2' ),
                                    array('name' => 'category 3' )
                            ), 
                            'repeat' => true
                    )

            ) );
            $r->generateReport ();
            $r->load ( array (
                    array (
                            'id' => 'i',
                            'data' => array (
                                    array ('name' => 'issue 1') ,
                                    array ('name' => 'issue 2'),
                                    array ('name' => 'issue 3'),
                                    array ('name' => 'issue 4'),
                            ),
                            'repeat' => true 
                    ) 
            ) );
            $r->generateReport ();

$r->renderXlsx()...

With template template But data render not like what I was expecting. data

dukec2020 commented 11 years ago

Resolved by do like this;

$r->load ( array (
        array (
            'id' => 'c',
            'data' => array (
                array (
                    'name' => 'cat 1',
                    'issue' => '{i1:name}' 
                ),
                array (
                    'name' => 'cat 2',
                    'issue' => '{i2:name}' 
                ) 
            )
            ,
            'repeat' => true 
        ) 
    ) );
    $r->generateReport ();
    $r->load ( array (
        array (
            'id' => 'i1',
            'data' => array (

                array (
                    'name' => 'iss 11' 
                ),
                array (
                    'name' => 'iss 12' 
                ) 
            )
            ,

            'repeat' => true 
        ) ,

        array (
            'id' => 'i2',
            'data' => array (

                array (
                    'name' => 'iss 21'
                ),
                array (
                    'name' => 'iss 22'
                )
            )
            ,

            'repeat' => true
        )
    ) );
    $r->generateReport ();