KoolReport's Forum

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

Data not exporting to Excel #3156

Open Alexandra Yusov opened this topic on on Sep 27, 2023 - 1 comments

Alexandra Yusov commented on Sep 27, 2023

Hello - I am trying to export data to excel. I have been following this guide https://www.koolreport.com/docs/excel/export_to_excel/#general-exporting-options .

It was printing all data as expected for a while but not now for some reason.

this is what i get:

(note that Account name, Currency, From and To data is exporting as expected - it is the only info that is exported).

Code:

public function settings()
    {
        return array(
            "dataSources" => array(
                "mainsource" => array(
                    "class" => '\koolreport\datasources\ArrayDataSource',
                    "dataFormat" => "table", //Table data format
                    "firstRowData" => true,
                    "typeEnclosures" => [
                        "string" => "\"",
                    ],
                    'data' => $this->params["data"],
                ),


            ),
            "BOM" => false,
        );
    }

    public function setup()
    {
        $this->src('mainsource')
            ->pipe(
                new \koolreport\processes\ColumnMeta(array(
                    "date" => array(
                        "type" => "string",
                        "label" => "Date"
                    ),
                    "service_description" => array(
                        "type" => "string",
                        "label" => "Service Description"
                    ),
                    "reference" => array(
                        "type" => "string",
                        "label" => "Reference"
                    ),
                    "debit" => array(
                        "type" => "number",
                        "label" => "Debit ($)",
                        "decimals" => 2,
                        "dec_point" => ".",
                    ),
                    "credit" => array(
                        "type" => "number",
                        "label" => "Credit ($)",
                        "decimals" => 2,
                        "dec_point" => ".",
                    ),
                    "balance" => array(
                        "type" => "string",
                        "label" => "Balance ($)",
                    )
                ))
            )->pipe($this->dataStore('AccountTransactions'));
    }
        try {
            $ReportGenerator = new ReportGenerator(
                array(
                    "data" => $data,
                    "fromDate" => $DateRange['FromDate'],
                    "toDate" => $DateRange['ToDate'],
                    'accountName' => $AccountName,
                    'currency' => $Currency->ShortForm,
                    'showBalanceSection' => $ShowBalanceSection,
                    'openingBalance' => $StartingBalance,
                    'closingBalance' => $EndingBalance,
                    'totalDebit' => $ShowBalanceSection ? strval($TotalDebit) : strval($PartialTotalDebit),
                    'totalCredit' => $ShowBalanceSection ? strval($TotalCredit) : strval($PartialTotalCredit),
                    'cellCordinates' => $CellCordinates
                ),
            );

            $ReportGenerator->run()
                ->exportToExcel('TransactionReport')
                ->saveAs($filePath);

(note: I am able to var dump and all variables have values)

view file:

<div sheet-name="Transaction Reports">
    <div cell="A1">
        <?php echo "Account Name"; ?>
    </div>
    <div cell="B1">
        <?php echo $this->params['accountName']; ?>
    </div>
    <div cell="A2">
        <?php echo "Currency"; ?>
    </div>
    <div cell="B2">
        <?php echo $this->params['currency']; ?>
    </div>
    <div cell="A4">
        <?php echo "From"; ?>
    </div>
    <div cell="B4">
        <?php echo $this->params['fromDate']; ?>
    </div>
    <div cell="A5">
        <?php echo "To"; ?>
    </div>
    <div cell="B5">
        <?php echo $this->params['toDate']; ?>
    </div>
    <div cell="A7">
        <?php echo "Total Debit"; ?>
    </div>
    <div cell="B7">
        <?php echo $this->params['totalDebit'] ?>
    </div>
    <div cell="A8">
        <?php echo "Total Credit"; ?>
    </div>
    <div cell="B8">
        <?php echo $this->params['totalCredit'] ?>
    </div>
    <?php if ($this->params['showBalanceSection'] === true) { ?>
        <div cell="A10">
            <?php echo "Opening Balance"; ?>
        </div>
        <div cell="B10">
            <?php echo $this->params['openingBalance'] ?>
        </div>
        <div cell="A11">
            <?php echo "Ending Balance"; ?>
        </div>
        <div cell="B11">
            <?php echo $this->params['closingBalance'] ?>
        </div>
    <?php } ?>
    <div cell="A12">
        <?php Table::create(array(
            "dataSource" => $this->dataStore('AccountTransactions'),
            "columns" => [
                "date" => array(
                    "label" => "Date"
                ),
                "service_description" => array(
                    "label" => "Service Description"
                ),
                "reference" => array(
                    "label" => "Reference"
                ),
                "debit" => array(
                    "label" => "Debit ($)"
                ),
                "credit" => array(
                    "label" => "Credit ($)"
                ),
                "balance" => array(
                    "label" => "Balance ($)"
                )
            ]
        )); ?>
    </div>
</div>

(note: I am able to echo the $this->params and I can see the values here)

Any assistance would be greatly appreciated. Thanks!

Alexandra Yusov commented on Sep 27, 2023

Solved the problem - the issue was not with Koolreport but rather than the way I was generating the $data param. can close ticket. thanks

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
help needed
solved

None