arodiss / XlsBundle

Trivia read and write of .xls files for Symfony2
MIT License
5 stars 9 forks source link

You have requested a non-existent service "arodiss.xls.reader" #20

Closed adigoun2005 closed 8 years ago

adigoun2005 commented 8 years ago

Hello I thank you for this bundle I am actually facing an issue i hope you can help me After the installation i am getting this error

Notice: Undefined variable: container

Here is my code

$em = $this->getDoctrine()->getManager();

$requested = $em->getRepository('UserBundle:User')->byRegister();

$writer = $this->get("arodiss.xls.writer.buffered"); $writer->create("futursVendeurOORUKA.xls", array("Nom d'utilisateur", "Nom","Prenoms","Email","Commune","Adresse","Complement","Telephone")); //second argument represents first row

foreach ($requested as $rq) { $writer->appendRow("users.xls", array($rq->getUser(), $rq->getUser()->getAdresses()->last()->getNom(), $rq->getUser()->getAdresses()->last()->getPrenoms(), $rq->getUser()->getEmail(), $rq->getUser()->getAdresses()->last()->getCommune(), $rq->getUser()->getAdresses()->last()->getAdresse(), $rq->getUser()->getAdresses()->last()->getComplement(), $rq->getUser()->getAdresses()->last()->getTelephone())); } $response = new Response(); $response->headers->set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); $response->headers->set("Content-Disposition", "attachment;filename=excelfile.xlsx"); $response->setContent(file_get_contents($file)); $response->send();

arodiss commented 8 years ago

Hi @adigoun2005

I see no $container variable in your code, so it is somewhere else. Can you please provide full error trace to give an insight? Also if this is snippet of Symfony controller, you should do return $response; at the very end instead of $response->send();

alarcia commented 6 years ago

Hello, I am experiencing this issue! I am very new with symfony. I just installed your bundle and was trying to test the very first sample code you wrote. I am using symfony4.

I need it to be in a Command class

$reader = $this->getContainer()->get('arodiss.xls.reader');
$content = $reader->readAll("C:/ArticlesInterior.xlsx");
var_dump($content);

Looks like I need to declare it in parameters.yaml, but I don't know what class I have to use, as no code was downloaded to my vendor folder with the composer installation.

    arodiss.xls.reader:
        class: ''
        public: true

Thank you very much @arodiss!

arodiss commented 6 years ago

Hello @alarcia One probable reason is that you did not register bundle in your application. I did not yet work with Symfony 4, but looks like in order to do it you have to add bundle in your 'config/bundles.php`