Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
930 views
in Technique[技术] by (71.8m points)

php - Using PHPExcel in CakePHP

Background

Well I tried to ask this question, but it got closed down faster than a horrible security leak. I want to write an excel file using PEAR's Spreadsheet Excel Writer. I Google'd endlessly for a easy way to do this, and finally found a helper that might actually do the job.

But it uses PHPExcel, so I'll have to rewrite that script, which is the least of my worries. I just don't want to start now, and then still not be able to get it working.

I have also downloaded PHPExcel as required by the helper.

What do I have?

I have the helper and I've added the helper to the controller like so:

public $helpers = array('PhpExcel.PhpExcel'); 

and I've created (copied and pasted) the script online into the view, just to test if it works.

What is the problem

I get an error:

Error: The application is trying to load a file from the PhpExcel plugin

Error: Make sure your plugin PhpExcel is in the appPlugin directory and was loaded

I have included the file in the APP/Vendor/PHPExcel.php folder (because I read somewhere that if the plugin doesn't follow the MVC framework, it needs to go in there) but it still doesn't work. Also tried it in the plugin directory and same error. This is the first time I'm using helpers (and hopefully not the last) so I'm pretty clueless with this.

I've also included the actual helper in the APP/View/Helper/ folder as PhpExcelHelper.php.

And the thing is I can't even get past step 1. Can someone tell me where the files need to go so that I can get this to work?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you take a peek in the Helper code you will notice that there is this function there called loadEssentials:

protected function loadEssentials() {
    // load vendor class
    App::import('Vendor', 'PHPExcel/Classes/PHPExcel');
    if (!class_exists('PHPExcel')) {
        throw new CakeException('Vendor class PHPExcel not found!');
    }
}

Now as you can see it looks in the Vendor folder for the PHPExcel library. What you should do is put the PHPExcel code in App/Vendor/. Then take a look at how to load vendor packages. Then the Helper should be in App/View/Helper and when you instantate it it should work. Also check the raed/write/excute permissions of the files in Vendor depending on your OS.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...