XLS content type

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 ?


.xls is the old file type used in XL 2003 and earlier. Excel for desktop still supports these file types and opens them in compatibility mode. Excel 2007 introduced the new XML based file types.

I doubt that the mobile version of Excel will ever support a file format that has been superseded over 7 years ago. Mobile Excel does not have the full feature set of desktop Excel, and compatibility mode is probably the least important thing on the backlog of things to catch up with.

Save your file as an XML based xlsx file. If constructed correctly, these will work fine on mobile Excel.

链接地址: http://www.djcxy.com/p/45468.html

上一篇: 文件在IE8上下载两次

下一篇: XLS内容类型