KoolReport's Forum

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

CSV and Excel Packages #2663

Closed Andre Van Der Walt opened this topic on on May 9, 2022 - 6 comments

Andre Van Der Walt commented on May 9, 2022

Good day

Can you please let me know when the Excel and CSV engines will be available as the documentation has been saying they will be available in the next version for a while now?

Sebastian Morales commented on May 10, 2022

Hi Andre, the latest version of Dashboard does support excel and csv export already. Here're the online example and source code for these features:

https://www.koolreport.com/dashboard/demo/?kdr=eyJyb3V0ZSI6IkFwcC9NYWluL0V4Y2VsQ1NWQm9hcmQiLCJhY3Rpb24iOiJpbmRleCJ9

https://github.com/koolreport/dashboard-demo/tree/main/src/excelcsv

Sorry for not updating the documentation for Dashboard's excel and csv export yet. We will upload it soon. Tks,

Andre Van Der Walt commented on May 10, 2022

I tried this.

Can you please guide me on where I'm going wrong?

My Report:

<?php

namespace namespace;


use path\AutoMaker;
use Illuminate\Support\Facades\DB;
use koolreport\dashboard\widgets\KWidget;

class ReportOne extends KWidget
{

    protected function dataSource()
    {
        $query = AutoMaker::procedure()->call(
            "db.GetData",[

            ]
        );
        return $query;
    }

    protected function onCreated()
    {
        $this
            ->use(\koolreport\datagrid\DataTables::class)
            ->settings([
                "paging"=>array(
                    "pageSize"=>10,
                ),
                "options"=>array(
                    "searching"=>true,
                    "colReorder"=>true,
                    "fixedHeader"=>false,
                    "select"=>true,
                    "paging"=>true,
                    "autoWidth" => false,
                    "responsive" => true,
                    "CSVExportable" => (true),
                    "ExcelExportable" => (true),
                ),
                "columns" => [
                    "Date",
                    "Name",
                    "Something",
                    "SomethingElse",
                ],
            ]);
    }
}

My Board:

<?php

namespace namespace;


use koolreport\dashboard\containers\Html;
use koolreport\dashboard\containers\Panel;
use koolreport\dashboard\containers\Row;
use \koolreport\dashboard\Dashboard;
use koolreport\dashboard\inputs\Dropdown;
use \koolreport\dashboard\widgets\Text;
use \koolreport\dashboard\inputs\Button;
use \koolreport\dashboard\Client;
use \koolreport\export\Exportable;
use \koolreport\excel\ExcelExportable;

class ReportOneBoard extends Dashboard
{
    protected function widgets()
    {
        return [
            Text::create()->text("
                    <br>
                    <h3>ReportOne</h3>
                    ")->asHtml(true),

            Row::create([
                Panel::create()->header("<b>Inbound Details with Recording</b>")->sub([
                    Html::div([
                        Dropdown::create("exporting")
                            ->title("Export")
                            ->align("right")
                            ->items([
                                Dropdown::menuItem()
                                    ->text("Export to Excel")
                                    ->icon("far fa-file-excel")
                                    ->onClick(
                                        Client::widget("ReportOne")
                                            ->exportToXLSX("ReportOne")
                                    ),
                                Dropdown::menuItem()
                                    ->text("Export to CSV")
                                    ->icon("fa fa-file-csv")
                                    ->onClick(
                                        Client::widget("ReportOne")
                                            ->exportToCSV("ReportOne")
                                    ),
                            ]),
                    ])->class("text-right"),
                    Text::create()->text("<br>")->asHtml(true),
                    ReportOne::create()
                        ->xlsxExportable(true)
                        ->csvExportable(true)
                ])->width(2/2),
            ]),

        ];
    }
}
Sebastian Morales commented on May 10, 2022

If you use KWidget pls add the following fields() and dataView() methods to it:

<?php

namespace namespace;


use path\AutoMaker;
use Illuminate\Support\Facades\DB;
use koolreport\dashboard\widgets\KWidget;

use \koolreport\dashboard\fields\Text; // add this field depending on your column type
use \koolreport\dashboard\fields\Number; // add this field depending on your column type

class ReportOne extends KWidget
{
    ...
    protected function fields()
    {
        return [
            Text::create("Name"),
            Number::create("Something"),
        ];
    }

    public function dataView()
    {
        $dataView = parent::dataView();
        $fields = $this->fields();
        return $dataView
                ->fields($fields); // exportable expects dataview's fields property
    }        
} 
Andre Van Der Walt commented on May 10, 2022

Is there something else I need to do for this to work?

I do not get any errors and can see from the developer tools that the event is initiated, but the onClick does not start the download.

Do you have to follow the setup process like with PDF and if so, is the below correct?

protected function export()
{
    return ExportHandler::create()
        ->storage(
            dirname(__DIR__)."/storage")
        ->csvEngine(
            LocalExport::create()
        )
        ->xlsxEngine(
            LocalExport::create()
        );
}
KoolReport commented on May 10, 2022

You should use another engine for xls and csv, the LocalExport is for PDF and image, you should do this:


                ->csvEngine(
                    \koolreport\dashboard\export\CSVEngine::create()
                )
                ->xlsxEngine(
                    \koolreport\dashboard\export\XLSXEngine::create()
                )

Let us know if you need further assistance.

Andre Van Der Walt commented on May 12, 2022

It's working now, thank you.

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

Dashboard