KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

How to export multiple report into one page #2518

Closed saiful opened this topic on on Jan 4, 2022 - 21 comments

saiful commented on Jan 4, 2022

hi, i have a page with 2 pivot tables from 2 different datasources, now im trying to export my report to excel & pdf into one page like this:

im still confused how to setup export pakages:

here is my code:

    public function fna_pdf()
    {
        $report_100             = new FNAFAD0001_100([
                                    "param1"=>$this->p1,
                                    "param2"=>$this->p2
                                ]);
        $report_200             = new FNAFAD0001_200([
                                    "param1"=>$this->p1,
                                    "param2"=>$this->2
                                ]);
        $report_100->run()
        ->$report_200->run()
        ->cloudExport("FNAFAD0001PDF")
        ->chromeHeadlessIo("xxxxxx")
        ->pdf()
        ->toBrowser("FINANCE_DAILY_REPORT.pdf");
    }
    
    public function fna_excel()
    {
        $report_100             = new FNAFAD0001_100([
                                    "param1"=>$this->p1,
                                    "param2"=>$this->p2
                                ]);
        $report_200             = new FNAFAD0001_200([
                                    "param1"=>$this->p1,
                                    "param2"=>$this->p2
                                ]);
        $report_100->run()
        ->$report_200->run()
        ->exportToExcel([
            "properties"=>[
                "title"=>"FINANCE DAILY REPORT"
            ]])
        ->toBrowser("FINANCE_DAILY_REPORT.xlsx");
    }
Sebastian Morales commented on Jan 4, 2022

Just use 2 PivotTable in your pdf and excel view. Here's a demo for exporting excel view with excel\PivotTable:

https://www.koolreport.com/examples/reports/excel/pivottable/

saiful commented on Jan 5, 2022

i think it's different, because i have 2 class (report_100 and report_200) that shoud be called once in export function.

Sebastian Morales commented on Jan 5, 2022

Pls try ReportDataSource to get datastores from other reports into the current one. Then you can export those datastores into one pdf or excel view:

https://www.koolreport.com/docs/datasources/reportdatasource/

saiful commented on Jan 5, 2022

it doesn't work, here is the result:

my project has 2 report in 1 process, (so i have to run both process, right?) here is the hirearchy:

I'm just having trouble in this export process, which has 2 report to run before export process :

i've tried to separate the report but it doens't work, too.

Sebastian Morales commented on Jan 5, 2022

Pls create the third report (report 3) which user 2 ReportDataSource of report 1 and 2. Then pipe report 1 and 2's datastores to report 3's datastores. Then you can export all datastores using report 3.

saiful commented on Jan 6, 2022

i have tried to create the third report, but i get this error:

what's wrong with my code?

export function: `

public function fna_excel()

{
    $report_export          = new FNA_EXPORT([
                                "param1"=>$this->p1,
                                "param2"=>$this->p2
                            ]);
     
    $report_export->exportToExcel("FNAEXCEL")
    ->toBrowser("FINANCE_DAILY_REPORT.xlsx");
}

third report class:


namespace App\reports\FNAFAD0001; require "FNAFAD0001_100.php"; require "FNAFAD0001_200.php";

class FNAFAD0001_EXPORT extends \koolreport\KoolReport {

public function settings()
{
    return 
    [
        "dataSources"=>[
            "FNAFAD0001_100"=>[
                "class"=>"/koolreport/datasources/ReportDataSource",
                "report"=>"FNAFAD0001_100",
                "params"=>[
                    "param1"=>$this->p1,
                    "param2"=>$this->p2
                ]
            ],
            "FNAFAD0001_200"=>[
                "class"=>"/koolreport/datasources/ReportDataSource",
                "report"=>"FNAFAD0001_200",
                "params"=>[
                    "session_id"=>$this->p1,
                    "location_cd"=>$this->p2
                ]
            ],
        ]
    ];
}

public function setup()
{
    // prepare data 
    $this->src("FNAFAD0001_100")
    ->pipe($this->dataStore("F100"));

    $this->src("FNAFAD0001_200")
    ->pipe($this->dataStore("F200"));
}

}


Sebastian Morales commented on Jan 6, 2022

Pls use the full namespace of the report datasource:

    "report"=>"\full\namespace\FNAFAD0001_100", //change this to your report namespace
saiful commented on Jan 6, 2022

here is the result:

Sebastian Morales commented on Jan 6, 2022

Pls read the documentation of ReportDataSource carefully. Here's one of its pipe example:

        $this->src('hardwareSaleReport')
        ->dataStore('sale') //We want to get data from "sale" data store of HardwareSaleReport
        ...
        ->pipe(this->dataStore('sale_of_hardware'));

Your pipes from report datasource are not correct:

    $this->src("FNAFAD0001_100")
    ->pipe($this->dataStore("F100"));

    $this->src("FNAFAD0001_200")
    ->pipe($this->dataStore("F200"));
saiful commented on Jan 6, 2022

my apologies, i need all of the data from both report, i think it just create pipe to new report.

saiful commented on Jan 6, 2022

can you please explain me where the dataStore("sale") come from? i have been reading this: https://www.koolreport.com/docs/datasources/reportdatasource/ but i can't find the dataStore("sale") in settings. is it part of the hardwareSaleReport from the sample?

Sebastian Morales commented on Jan 6, 2022

Datastore "sale" is in hardwareSaleReport report. Basically with ReportDataSource you can pipe all datastores from the report datasource to the current report's datastores.

saiful commented on Jan 6, 2022

i have been pipe all data to new report. but when i try to export, the result looks like this:

Sebastian Morales commented on Jan 6, 2022

Pls print out the datastores' data of your 3rd report in your report view first to make sure you get full data from report 1 and 2.

saiful commented on Jan 7, 2022

i use properties in exportToExcel function and this is the result:

i have been using new report view based this sample too: https://www.koolreport.com/examples/reports/excel/pivottable/ but the result looks like this:

Sebastian Morales commented on Jan 7, 2022

Pls use excel view with excel PivotTable widget instead of direct datastore export.

saiful commented on Jan 7, 2022

i already use it:

<?php
    use \koolreport\excel\PivotTable;
    $sheet1 = "Finance Daily Report";
?>
<meta charset="UTF-8">
<meta name="title" content="Finance Daily Report">

<div sheet-name="<?php echo $sheet1; ?>">
    <?php
    $allStylesArray = [
        'font' => [
            'name' => 'Calibri', //'Verdana', 'Arial'
            'size' => 30,
            'bold' => false,
            'italic' => FALSE,
            'underline' => 'none', //'double', 'doubleAccounting', 'single', 'singleAccounting'
            'strikethrough' => FALSE,
            'superscript' => false,
            'subscript' => false,
            'color' => [
                'rgb' => '000000',
                'argb' => 'FF000000',
            ]
        ],
        'alignment' => [
            'horizontal' => 'general',//left, right, center, centerContinuous, justify, fill, distributed
            'vertical' => 'bottom',//top, center, justify, distributed
            'textRotation' => 0,
            'wrapText' => false,
            'shrinkToFit' => false,
            'indent' => 0,
            'readOrder' => 0,
        ],
        'borders' => [
            'top' => [
                'borderStyle' => 'none', //dashDot, dashDotDot, dashed, dotted, double, hair, medium, mediumDashDot, mediumDashDotDot, mediumDashed, slantDashDot, thick, thin
                'color' => [
                    'rgb' => '808080',
                    'argb' => 'FF808080',
                ]
            ],
            //left, right, bottom, diagonal, allBorders, outline, inside, vertical, horizontal
        ],
        'fill' => [
            'fillType' => 'none', //'solid', 'linear', 'path', 'darkDown', 'darkGray', 'darkGrid', 'darkHorizontal', 'darkTrellis', 'darkUp', 'darkVertical', 'gray0625', 'gray125', 'lightDown', 'lightGray', 'lightGrid', 'lightHorizontal', 'lightTrellis', 'lightUp', 'lightVertical', 'mediumGray'
            'rotation' => 90,
            'color' => [
                'rgb' => 'A0A0A0',
                'argb' => 'FFA0A0A0',
            ],
            'startColor' => [
                'rgb' => 'A0A0A0',
                'argb' => 'FFA0A0A0',
            ],
            'endColor' => [
                'argb' => 'FFFFFF',
                'argb' => 'FFFFFFFF',
            ],
        ],
    ];
    $styleArray = [
        'font' => [
            'italic' => true,
            'color' => [
                'hex' => 'a83234',
            ]
        ],
    ];
    ?>
    <div>Finance Daily Report</div>
    <div>Summary
        <div>
        <?php
        PivotTable::create(array(
            "dataSource" => $this->dataStore('F100'),
            'hideSubTotalRows' => true,
            'hideSubTotalColumns' => true,
            'hideGrandTotalRow' => true,
            'hideGrandTotalColumn' => true,
            "showDataHeaders" => true,
            'map' => array(
                'rowField' => function($rowField, $fieldInfo) {
                    return $rowField;
                },
                'columnField' => function($colField, $fieldInfo) {
                    return $colField;
                },
                'dataField' => function($dataField, $fieldInfo) {
                    // Util::prettyPrint($fieldInfo);
                    return $dataField;
                },
                'dataHeader' => function($dataField, $fieldInfo) {
                    // Util::prettyPrint($fieldInfo);
                    return $dataField;
                },
                'waitingField' => function($waitingField, $fieldInfo) {
                    return $waitingField;
                },
                'rowHeader' => function($rowHeader, $headerInfo) {
                    // Util::prettyPrint($headerInfo);
                    $v = $rowHeader;
                    if (isset($headerInfo['childOrder']))
                        $v = $headerInfo['childOrder'] . ". " . $v;
                    return $v;
                },
            ),
            'excelStyle' => array(
                'dataField' => function($dataFields) use ($styleArray) {
                    return $styleArray;
                },
                'dataHeader' => function($dataFields, $fieldInfo) use ($styleArray) {
                    return $styleArray;
                },
                'columnHeader' => function($header, $headerInfo) use ($styleArray) {
                    return $styleArray;
                },
                'rowHeader' => function($header, $headerInfo) use ($styleArray) {
                    return $styleArray;
                },
                'dataCell' => function($value, $cellInfo) use ($styleArray) {                    
                    return $styleArray;
                },
            )
        ));
        ?>
        </div>
    </div>

    <div>Detailed
        <div>
        <?php
        PivotTable::create(array(
            "dataSource" => $this->dataStore('F200'),
            'hideSubTotalRows' => true,
            'hideSubTotalColumns' => true,
            'hideGrandTotalRow' => true,
            'hideGrandTotalColumn' => true,
            "showDataHeaders" => true,
            'excelStyle' => array(
                'dataField' => function($dataFields) use ($styleArray) {
                    return $styleArray;
                },
                'dataHeader' => function($dataFields, $fieldInfo) use ($styleArray) {
                    return $styleArray;
                },
                'columnHeader' => function($header, $headerInfo) use ($styleArray) {
                    return $styleArray;
                },
                'rowHeader' => function($header, $headerInfo) use ($styleArray) {
                    return $styleArray;
                },
                'dataCell' => function($value, $cellInfo) use ($styleArray) {                    
                    return $styleArray;
                },
            )
        ));
        ?>
        </div>
    </div>
    
</div>
saiful commented on Jan 7, 2022

I'm still get result like this:

Sebastian Morales commented on Jan 7, 2022

You put excel PivotTable in a 3rd level div. Excel export view only recognizes 2 div levels, the 1st one is for sheets, 2nd one is for widget.

saiful commented on Jan 7, 2022

i removed the 3rd div, this is the result:

Sebastian Morales commented on Jan 7, 2022

Pls check the data of your $this->dataStore('F200') in your report view (not excel view). For example:

//MyReport3.view.php
print_r($this->dataStore('F200')->data());

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

CloudExport