Export to Excel

I am facing issue with export to excel. I am using codeigniter 4 GroceryCRUD 2.9.2, However export to pdf and print works as expected. The error details.

ErrorException

Required parameter $pValue follows optional parameter $pCoordinate

  1. APPPATH\Libraries\GroceryCrudEnterprise\scoumbourdis\phpexcel\Classes\PHPExcel\Autoloader.php : 79 — CodeIgniter\Debug\Exceptions->errorHandler
$severity 8192
$message Required parameter $pValue follows optional parameter $pCoordinate
$file D:\webdevelopment\08-08-2021_New_Build\30-10-2021\ci4\app\Libraries\GroceryCrudEnterprise\scoumbourdis\phpexcel\Classes\PHPExcel\Worksheet.php
$line 1477
  1. APPPATH\Libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\State\ExportState.php : 195 — GroceryCrud\Core\State\ExportState->exportToExcel ( arguments )
    $data

Array
(
[0] => Array
(
[userid] => test
[scheme] => Replacement of Old Pumpsets
[office] => CUDDALORE
[insdate] =>
[officer] =>
[workcompleted] =>
[document] =>
[invoice] =>
[paymentcompleted] =>
[central] =>
[state] =>
[farmer] =>
)

)

$columns

Array
(
[0] => stdClass Object
(
[name] => userid
[displayAs] => Farmer Name
)

[1] => stdClass Object
    (
        [name] => scheme
        [displayAs] => Scheme
    )

[2] => stdClass Object
    (
        [name] => office
        [displayAs] => Office
    )

[3] => stdClass Object
    (
        [name] => insdate
        [displayAs] => Inspection Date
    )

[4] => stdClass Object
    (
        [name] => officer
        [displayAs] => Inspection Official
    )

[5] => stdClass Object
    (
        [name] => workcompleted
        [displayAs] => Work Completed (Yes / No)
    )

[6] => stdClass Object
    (
        [name] => document
        [displayAs] => Inspection Document
    )

[7] => stdClass Object
    (
        [name] => invoice
        [displayAs] => Invoice
    )

[8] => stdClass Object
    (
        [name] => paymentcompleted
        [displayAs] => Payment Completed (Yes / No)
    )

[9] => stdClass Object
    (
        [name] => central
        [displayAs] => Central Share Relesed (Rs.)
    )

[10] => stdClass Object
    (
        [name] => state
        [displayAs] => State Share Relesed (Rs.)
    )

[11] => stdClass Object
    (
        [name] => farmer
        [displayAs] => Farmer Share Relesed (Rs.)
    )

)

Kindly help.

Hello @vallstn and welcome to our forums :hugs:

We’ve tracked this issue that the export to excel doesn’t work for PHP 8. Can you please confirm that the version of PHP is version 8 or later? I will try to fix this issue for the next release.

Regards
Johnny

Yes I am using PHP 8.0.11, Thanks for immediate response. I am waiting for next update.

Hello @vallstn ,

I am glad to inform you that the latest version of Grocery CRUD Enterprise (2.9.3) now includes the fix for the export to excel. In order to download the latest version visit the page: User's Page Login

Let me know if that worked for you.

Regards
Johnny

Thanks Johnny,

Now it is working.

Regards,
Vallstn

1 Like

Hi,

I’ve just downloaded the latest version (grocery-crud-enterprise-with-codeigniter-4-v2.9.3.zip), and still have the same issue of the previous version regarding export to Excel: ERR_INVALID_RESPONSE

Basically,
This works: https://my_site/public/index.php/main/referencias?action=export-pdf&page=1&per_page=10&order_by=referencia&sorting=asc

This doesn’t work: http://my_site/public/index.php/main/referencias?action=export&page=1&per_page=10&order_by=referencia&sorting=asc

Can you please provide me some advice ?

Thank you in advance.
Sérgio

Hello @sbaltaz and sorry for the delay,

I couldn’t reproduce the issue but after updating PHP to version 8.1 the issue is now reproducible. Can you please confirm that the PHP version that you use is 8.1?

I’ve fixed some issues with PHP 8.1 for 2.9.3 but I am still investigating on this one.

Regards
Johnny

Hello @johnny,

Thank you for your answer.
I’m using PHP 7.4.3.

In the meanwhile, while you’re working on this issue, can you please tell me in which PHP version both exports are working correctly ?

Thank you.

Best regards
Sérgio

Hello @sbaltaz ,

I am glad to inform you that I’ve fixed the issue and you can find it available on the latest version (2.9.4). The fixes are as following:

  1. Version 2.9.3 is fixing the issues that we had for PHP 8.0
  2. Version 2.9.4 is fixing the issues that we had for PHP 8.1

Regards
Johnny

Hello @johnny,

Thank you for your time and work.
I’ll give a try to the next version and let you know the results.

Best regards,
Sérgio

Hello @johnny,

I’d like to inform you that Version 2.9.4 fixes the excel’s exportation problems, in PHP 7.4.3. :clap:
Thank you for your time and good work. :+1:

Best regards,
Sérgio

1 Like

Hi @johnny ,

some of my grids are exporting in php 8.1 some of them not. I guess is because the grids that are not exported contains a date field.

here are my findings:
grep -r --include=“*.php” strftime .
./scoumbourdis/phpexcel/Classes/PHPExcel/Calculation/DateTime.php: $testVal3 = strftime(‘%Y’);
./scoumbourdis/phpexcel/Classes/PHPExcel/Calculation/DateTime.php: $PHPDateArray[‘year’] = strftime(‘%Y’);
./scoumbourdis/phpexcel/Classes/PHPExcel/Calculation/DateTime.php: $PHPDateArray[‘month’] = strftime(‘%m’);
./scoumbourdis/phpexcel/Classes/PHPExcel/Calculation/DateTime.php: $PHPDateArray[‘day’] = strftime(‘%d’);

I solved by adding the error_reporting line in ./grocerycrud/enterprise/src/GroceryCrud/Core/State/ExportState.php,
but I don’t know for why just worked …

public function exportToExcel($data, $columns)
{
    error_reporting(E_ERROR | E_WARNING | E_PARSE);

KR,
Gabriel

Hello @GabrielD ,

Yes you are right, this is one more issue with PHP 8.1 (or PHP 7 in your case?) . Specifically if the value is a float number. I’ve fixed that on the PHP Excel repo: Fixing issue with PHP 8.1 deprecated error "Implicit conversion from … · scoumbourdis/PHPExcel@e43a89c · GitHub

Now from your findings we may also have the same issues with dateTime? I will investigate and let you know.

Thanks for the update @GabrielD by the way, it really helped :grinning: As PHPExcel is deprecated I am trying to do all the updates myself and it is hard to keep track of every new deprecation from PHP 8 (or even in some cases PHP 7)

2 Likes

Time to switch to a supported, maintained full JS solution, like SheetJS Community Edition | SheetJS Community Edition.

This only works if you use the datatable theme, but maybe it could be adapted to flexygrid.

    $("#exportExcel").click(function (event) {
        //obtain reference to table obj
        var table_id = $("table:first").attr("id");

        //get data from datatable 
        var header = Array();
        var data = $('#' + table_id).DataTable().fnGetData();

        //add headers
        $("table:first thead tr th").each(function (i, v) {
            header[i] = $(this).text();
        });
        data.unshift(header);

        //remove action column
        data = data.map(data => data.slice(0, -1));

        // create Sheetjs object
        var ws = XLSX.utils.aoa_to_sheet(data);
        var wb = XLSX.utils.book_new();



// Add the worksheet to the workbook 
        XLSX.utils.book_append_sheet(wb, ws, "Vendor classification");

//create and downloading workbook
        var today = new Date();
        var dd = String(today.getDate()).padStart(2, '0');
        var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
        var yyyy = today.getFullYear();

        //download file
        var filename = dd + '.' + mm + '.' + yyyy + '_vendor_class.xlsx';
        XLSX.writeFile(wb, filename);




        //alert("Export tabella in corso, controllare i download");
        // location.reload();

    });