1

i wanna import and view excel file using php, so i have a found a library class php-excel-reader

when we use php, we just include the file in the page using include("nameoffile.php");

i don't know how to do that using symfony. where should i import ? and how?`

3
  • Symfony actually is PHP, so the exact same thing technically works as well so I wonder a bit what you want to know about specifically. Commented May 30, 2012 at 13:24
  • you can add this Bundle: github.com/liuggio/ExcelBundle Commented May 30, 2012 at 17:51
  • thank you, i added the bundle, and it work great! thank's for ur answer ^^ Commented May 30, 2012 at 18:50

2 Answers 2

2

This is for PHPExcel as opposed to the reader but the principle is the same. No need to actually include files. They can be autoloaded.

Add to your autoload.php:

$loader->registerPrefixes(array(
    'Twig_Extensions_' => $ws.'Symfony/vendor/twig-extensions/lib',
    'Twig_'            => $ws.'Symfony/vendor/twig/lib',
    'Zend_'            => $ws.'ZendFramework-1.11.11/library',
    'PHPExcel'         => $ws.'PHPExcel/Classes' // Change to support the reader
));

After which you can do something like:

$reader = new \Spreadsheet_Reader();

Note the leading slash is required to handle the non-namespaced library.

I abstracted things just a bit by using a service:

/* ==================================================
 * Wrap interface to the excel spreasheet processing
 */
namespace Zayso\CoreBundle\Component\Format;

class Excel
{
    public function newSpreadSheet()
    {
        return new \PHPExcel();
    }
    public function newWriter($ss)
    {
        return \PHPExcel_IOFactory::createWriter($ss, 'Excel5');
    }
    public function load($file)
    {
        return \PHPExcel_IOFactory::load($file);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can create a service which require a file. You have an example in the official documentation.

2 Comments

At the moment there is no such example in documentation :(
My bad. Seems that the example have been moved here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.