KoolReport's Forum

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

Setting style export excel #2503

Open hayu opened this topic on on Dec 19, 2021 - 3 comments

hayu commented on Dec 19, 2021

hi, I'm creating API export data to excel from a data array and I use the action saveAs(), I want to ask how do I set the spreadsheet style (font-style, bold_yn, font_size, align etc.) when exporting to excel without a template? because in the documentation to set the style must include in table::create

Sebastian Morales commented on Dec 20, 2021

Excel style and big spreadsheet style are currently only available with Excel Table widget in excel view. We will find a way for you to use them directly when exporting datastores. We will post update in this topic for you. Rgds,

hayu commented on Dec 20, 2021

Thank you for replying to my question, I'm waiting for the next update.

Sebastian Morales commented on Dec 21, 2021

We will support all properties of Excel Table/PivotTable/PivotMatrix when exporting a datastore directly to excel in the next version. Meanwhile, you could try this method:

1 . Open the file koolreport/excel/ExportHandler.php and replace the following lines:

            $config['sheets'][] = [
                'name' => $name,
                'contents' => [
                    [
                        'type' => $type,
                        'dataSource' => $dataStore
                    ]
                ]
            ];       

with these ones:

            $content = array_merge(Util::get($options, $name, []), [
                'type' => $type,
                'dataSource' => $dataStore
            ]);
            $config['sheets'][] = [
                'name' => $name,
                'contents' => [ $content ]
            ];

2 . Then in your export page use this command:

$report
->run()
->exportToExcel([
    "dataStores" => [
        "orders" => [
            "filtering" => function($row, $index) { 
                if (stripos($row['customerName'], "Baane Mini Imports") !== false)
                    return false;
                return true;
            },
            "sorting" => ['dollar_sales' => 'desc'],
            "paging" => [5, 2],
            "showHeader" => false, //default: true
            "showBottomHeader" => true, //default: false
            "showFooter" => true, //default: false
            "map" => [
                "header" => function($colName) { return $colName; },
                "bottomHeader" => function($colName) { return $colName; },
                "cell" => function($colName, $value, $row) { return $value; },
                "footer" => function($colName, $footerValue) { return $footerValue; },
            ],
            "excelStyle" => [
                "header" => function($colName) { 
                    return [
                        'font' => [
                            'italic' => true,
                            'bold' => false,
                            'color' => [
                                'rgb' => '808080',
                            ]
                        ],
                    ]; 
                },
                "bottomHeader" => function($colName) { return []; },
                "cell" => function($colName, $value, $row) { 
                    return [
                        'font' => [
                            'italic' => true,
                            'color' => [
                                'rgb' => '808080',
                            ]
                        ],
                    ]; 
                 },
                "footer" => function($colName, $footerValue) { return []; },
            ]
        ]
    ]
])
->toBrowser("MyReport.xlsx"); 

Let us know the result. Tks,

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

Export