KoolReport's Forum

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

Right To Left Excel Export #1420

Closed gentlegriffon opened this topic on on May 3, 2020 - 7 comments

gentlegriffon commented on May 3, 2020

Hello, As the title says, I need a way to render excel sheet (export) as a right to left sheet. How can I do this?

Thanks

David Winterburn commented on May 4, 2020

Please try this in your excel export template and let us know the result:

//MyReportExcel.view.php
$emptyStyleArray = [];
$rightStyleArray = [
    'alignment' => [
        'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT,
    ]
];

Table::create(array(
    ...
    "excelStyle" => [
        "header" => function($colName) { 
            return $emptyStyleArray; 
        },
        "cell" => function($colName, $value, $row) { 
            if ($colName === 'My right alignment column')
                return $rightStyleArray; 
            else 
                return $emptyStyleArray;
         },
        "footer" => function($colName, $footerValue) { 
            return $emptyStyleArray; 
        },
    ]
    ...
));
gentlegriffon commented on May 4, 2020

Hello It didn't work, I also tried to use $rightStyleArray in all occurrences without condition but didn't work. Note that the whole sheet should be right to left not just columns. This highlighted option is expected to be activated

David Winterburn commented on May 5, 2020

Do you have the latest version (7.1.1) of the Excel package (look in excel/composer.json)? And please post your excel template php code for us to check it for you. Thanks!

gentlegriffon commented on May 5, 2020

Here it is:

{

"name": "koolreport/excel",
"version":"7.0.0",
"description": "Allow KoolReport to connect to Excel and export to excel file",
"keywords": ["PHP","Reporting Tools","Data Report","Charts","Exporting","Microsoft Excel","XLS","Export to Excel"],
"homepage": "https://www.koolreport.com",
"type": "library",
"license": "https://www.koolreport.com/license#mit-license",
"require": {
    "phpoffice/phpspreadsheet": "^1.6",
    "box/spout": "^3.0"
}

}

thanks

David Winterburn commented on May 6, 2020

Please update Excel package to the latest version (7.1.1) and try again. If it still doesn't work please post your excel template code for us here for us to check it for you. Thanks!

gentlegriffon commented on May 6, 2020

I did just now, I downloaded the latest one from my licenses. Now I have

{
    "name": "koolreport/excel",
    "version":"7.1.1",
    "description": "Allow KoolReport to connect to Excel and export to excel file",
    "keywords": ["PHP","Reporting Tools","Data Report","Charts","Exporting","Microsoft Excel","XLS","Export to Excel"],
    "homepage": "https://www.koolreport.com",
    "type": "library",
    "license": "https://www.koolreport.com/license#mit-license",
    "require": {
        "phpoffice/phpspreadsheet": "^1.6",
        "box/spout": "^3.0"
    }
}

but this didn't fix the problem :/

here is the code to review:


    <!-- render table -->
    <?php
        $emptyStyleArray = [];
        $rightStyleArray = [
            'alignment' => [
                'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT,
            ]
        ];
        Table::create(array(

            "dataStore"=>$this->dataStore('Journal Vouchers Report'),
            "cssClass"=>array(
                "table"=>"table table-hover table-bordered table-striped"
            ),
            "excelStyle" => [
            "header" => function($colName) { 
                return $rightStyleArray; 
            },
            "cell" => function($colName, $value, $row) { 
                return $rightStyleArray; 
             },
            "footer" => function($colName, $footerValue) { 
                return $rightStyleArray; 
            },
        ]
          
        ));
    ?>
David Winterburn commented on May 7, 2020

I forgot the "use" keyword to use an outside variable in a function. Please try this and let us know the result:


    <!-- render table -->
    <?php
        $emptyStyleArray = [];
        $rightStyleArray = [
            'alignment' => [
                'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT,
            ]
        ];
        Table::create(array(

            "dataStore"=>$this->dataStore('Journal Vouchers Report'),
            "cssClass"=>array(
                "table"=>"table table-hover table-bordered table-striped"
            ),
            "excelStyle" => [
            "header" => function($colName) use ($rightStyleArray) { 
                return $rightStyleArray; 
            },
            "cell" => function($colName, $value, $row) use ($rightStyleArray)  { 
                return $rightStyleArray; 
             },
            "footer" => function($colName, $footerValue) use ($rightStyleArray)  { 
                return $rightStyleArray; 
            },
        ]
          
        ));
    ?> 

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

Excel