KoolReport's Forum

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

Switch datasource from CSV to Excel file #2241

Closed hsw opened this topic on on Jul 30, 2021 - 10 comments

hsw commented on Jul 30, 2021

Hi,

I tried to switch my datasource from CSV file to Excel file. Thought I just need to simply change the datasource settings, and the rest of the codes with all the processes in setup to remain unchanged.

But the report is not working after that.

I already have the excel package installed, as I can see the excel folder.

Can someone highlight what other changes I need to make?

Thank you

Sebastian Morales commented on Jul 30, 2021

The problem could be difference between CSV and Excel in date and number formats. Pls turn on your PHP error reporting to E_ALL and let us know if there's any warning or error message. If you have screenshots of the problem after changing to Excel datasource pls post them as well. Rgds,

hsw commented on Jul 30, 2021

Hi,

The error is: My site is currently unable to handle this request. HTTP ERROR 500.

I added "error_reporting(E_ALL);" at the top of my php file. But still not able to see any error messages.

Sebastian Morales commented on Jul 30, 2021

Pls remove almost all of your report's setup content, only keep one command like this:

function settings()
{
    // set excel data source here ...
}
function setup()
{
    $this->src("excelDatasource")
    ->pipe($this->dataStore("myDatastore"));
}

Then in your report view use only a table widget to display myDatastore's data. Let us know the result. Rgds,

hsw commented on Jul 30, 2021

Hi

Thanks for the guidance. Followed your suggestion, and encountered the same error - HTTP ERROR 500.

Below are my codes.

index.php file:

error_reporting(E_ALL);

require_once "Compare.php";
$report = new Compare;

$report->run()->render();

Compare.php file:

error_reporting(E_ALL);

// Require autoload.php from koolreport library
require_once "../koolreport/core/autoload.php";

//Specify some data processes that will be used to process
use \koolreport\excel\ExcelDataSource;
        
//Define the class
class Compare extends \koolreport\KoolReport
{    
    use \koolreport\bootstrap3\Theme;

    protected function settings()
    {
		//Define the "packages" data source in excel file
		return array(
            "dataSources"=>array(
                "packages"=>array(
                    "class"=>'\koolreport\excel\ExcelDataSource',
                    'filePath'=>"hl_mpackages.xlsx",
                    'firstRowData'=>false,
                ),
            )
        );
    }
  
    protected function setup()
    {
         $this->src("packages")
            ->pipe($this->dataStore("myDatastore"));
            
    }
}

Report view: `

use \koolreport\widgets\koolphp\Table;

Table::create(array(
"dataStore"=>$this->dataStore('myDatastore')

));


Thank you.
Sebastian Morales commented on Aug 2, 2021

It's quite hard to debug without a specific error message. Http 500 error is too general. Pls open your php.init file and make sure that display_errors = On. Also let us know the following information:

1 . What is your web server (Apache, Nginx, etc) and its version 2 . What is your PHP version? 3 . Do you use any PHP framework (such as Laravel, Symphony, etc) ? 4 . What is your KoolReport Excel package version?

Tks,

hsw commented on Aug 3, 2021

Hi,

1 . What is your web server (Apache, Nginx, etc) and its version. Apache

2 . What is your PHP version? php 5.6

3 . Do you use any PHP framework (such as Laravel, Symphony, etc) ? No.

4 . What is your KoolReport Excel package version? I downloaded KoolReport v4 last year, with all the packages. Not sure how to check the Excel package version.

If switching to Excel needs to take up more time, I need to reconsider.

Before I decide whether to explore the Excel package further, may i know from your experience in KoolReport, what are the pros and cons of using csv vs excel datasource?

Thank you.

Sebastian Morales commented on Aug 4, 2021

You could find a package version from its compose.json file (a text json file, with a version field). For a datasource, CSV is better than Excel because its simpler and faster to read. Rgds,

hsw commented on Aug 4, 2021

Hi,

Appreciate very much for your response so far.

The Excel package ver is 8.0.1. Is there any incompatibility issue?

Thank you.

Sebastian Morales commented on Aug 5, 2021

Oh, since Excel package version 7.1.0 PHP version must be >= 7.1 because we updated the PHPSpreadsheet library version in it. If you still want to use PHP 5.6, pls use Excel package version <= 7.0. Rgds,

hsw commented on Aug 6, 2021

Ok 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

Excel