PHPExcel breaks the page in wordpress

I’m trying to use the library PHPExcel inside wordpress.

I created a class to parse the csv file, but just call the method to read the file PHPExcel_IOFactory::load($file) or even to identify the file, page breaks.

Read More

The problem is that I do not get any results, only the blank page.

Not even on the apache log errors occur.

The class is this:

require('vendor/PHPExcel/Classes/PHPExcel/IOFactory.php');

class parseCsv {

    protected $file;
    protected $fileType;

    public function __construct($file)
    {
        $this->file = $file;
        $this->fileType = PHPExcel_IOFactory::identify($this->file);

    }

    public function parseCsv()
    {
        $objReader = PHPExcel_IOFactory::createReader($this->fileType);
        $objPHPExcel = $objReader->load($this->file);
        $objWorksheet = $objPHPExcel->getActiveSheet();
        foreach ($objWorksheet->getRowIterator() as $row) {
            $cellIterator = $row->getCellIterator();
            $cellIterator->setIterateOnlyExistingCells(false);
            foreach ($cellIterator as $cell) {
                $cell_value = $cell->getValue();
                var_dump($cell_value);
            }
        }
    }

} 

Definitely something wrong but I can not figure out where.

EDIT

Instantiate the class name in the file functions.php in wp-content/themes/myproject in this way:

function exec_at_init()
{
    ...
    require('helpers/parse/parse.php');
}
function create_regcontabilita()
{
    $parse = new parse('helpers/parse/matrice.csv');
    $parse->parseCsv();
}

Related posts

Leave a Reply

2 comments

  1. If the page breaks thats probably an error 500

    Please check the response status (inspect element in chrome, network tab) after refreshing the page.

    If the status is 500 then maybe is a php script error.
    If that is the case, the page is blank because of the php.ini error_reporting configuration maybe is set to hide some errors.

    add this to the start of your script and try.

    error_reporting(E_ALL);