XLS content type – mobile devices

My Laravel 4.2 php project has export to excel feature, which is working on desktop but totally not working on mobile devices. I am saving the excel file with “XLS” extension and “application/vnd.ms-excel” content type:

       $fn = 'filename.xls';
       $filename = storage_path() . '/' . $fn;

        App::finish(function($request, $response) use ($filename) {
            unlink($filename);
        });

        $headers = array(....);

        $excel = new Excel();
        $excel->setTheader($headers);
        $excel->addArray(..);
        $excel->generateXML($filename);

        return Response::download($filename, $fn, array('Content-Type' => 'application/vnd.ms-excel; charset=utf-8'));

So on my iphone I have Microsoft Excel installed but my phone raises this error:

an error occurred while reading the document

Clicking on “open with excel” I get this:

excel cannot open this workbook

When I changed the content type to

application/octet-stream

the excel file got opened but like a text file.

What am I doing wrong, is the problem in my application or in my phone ?


Source: laravel

Leave a Reply