1

I just want to display a Excel file existing on my hardisk in a twig view.

I'm using Symfony[2.5] and "Liuggio/Excelbundle"

This trick works well but i want to add it in my view.

 public function newAction()
    {
        $filename = 'filename.xlsx';
        $reader = \PHPExcel_IOFactory::createReaderForFile($filename);
        $excel = $reader->load($filename);
        $writer = \PHPExcel_IOFactory::createWriter($excel, "HTML");

        $writer->generateStyles();
        $writer->generateSheetData();

// this doesnt work..
        return $this->render('MonextReportingBundle:Default:excel.html.twig', array(
            'excelHtml'=>$writer
    ));

And in my excel.html.twig :

{{ excelHtml | raw }}

Catchable fatal error: Object of class PHPExcel_Writer_HTML could not be converted to string

Thanks a lot guys ! Excuse my english..

2
  • Did you try excelHtml.generateSheetData | raw? Commented Dec 30, 2016 at 15:32
  • @Maerlyn it works great ! thanks a lot Commented Dec 30, 2016 at 15:50

1 Answer 1

1

PHPExcel's HTML writer has no toString(), that's why your attempt didn't work.

It has, however, a method called generateSheetData that seems to do what you want. Use it like this:

{{ excelHtml.generateSheetData | raw }}
Sign up to request clarification or add additional context in comments.

2 Comments

Maerlyn, do you know how to set Max column ? I want to display only 14 columns in my HTML table. I dont know how to implement a Filter inside my newAction function.. Thanks a lot.
@SimonDelaunay if you have a question, ask a question

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.