문제

Background

I have issues using PHPExcel's IOFactory in my app. My PHPExcel helper works if I want to generate an excel document from scratch (my app creates about 20 excel sheets per week, with no issues).

Why do you need It?

I need to now combine some sheets (uploaded and generated to a general sheet and then send that off to who-ever. Problem is that all the sheets are generated by a different person. So they upload all these sheets to the app, and it combines the sheets and sends it out.

What's the problem then?

In my PHPExcelHelper.php file, I've added the following function:

public function createMasterFile($ExcelFile) {
    $MasterFile = PHPExcel_IOFactory::load($ExcelFile);
    return $MasterFile;
}

This is basically just supposed to take a file, to which it will add all the other files as spreadsheets. I'm using this question as a guide.

However, it throws the following error:

Error: Class 'PHPExcel_IOFactory' not found 

This tells me that it can't find that class (duh) and that I need to include it.

What have you tried?

I've tried to add it directly by adding require_once('PHPExcel/IOFactory.php'); to the end of the PHPExcel.php file located in the Vendors-folder. No luck.

Then I tried adding it to my loadEssentials()-function in my PHPExcelHelper.php-file, which was like this one and then I just added this:

App::import('Vendor', 'PHPExcel/IOFactory');
if (!class_exists('PHPExcel/IOFactory')) {
    throw new CakeException('Vendor class IOFactory not found!');
}

No luck.

And I've also tried calling it by using public $helpers = array('PHPExcel','PHPExcel/IOFactory'); in my Controller, but this just asked for a helper which didn't exist. So that also gave me no luck.

What do you want from us?

Any assistance in getting this to work really. I have tried what I thought would be the logical ways to include IOFactory, but have had no success. Could someone please show me how to get PHPExcel's IOFactory to work?

도움이 되었습니까?

해결책

assuming your folder structure is like this

App
    Vendor
        PHPExcel
            PHPExcel.php
            PHPExcel
                IOFactory.php

you should use

App::import('Vendor', 'PHPExcel', array('file' => 'PHPExcel'.DS.'PHPExcel.php'));
App::import('Vendor', 'PHPExcel_IOFactory', array('file' => 'PHPExcel'.DS.'PHPExcel'.DS.'IOFactory.php'));

다른 팁

put this line on top of the page

App::import('Vendor', 'PHPExcel', array('file' => 'excel/PHPExcel.php'));

plz change vendor path.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top