A file is in a different file format than its extension indicates - Problem

Topics: Developer Forum, User Forum
Oct 1, 2010 at 1:52 PM

Hi all,

I'm successful added PHPExcel class to my project and export works fine to my in most of the cases, except few exports are broken not really broken but, when system try to open file

I get this message "....the file 'FILENAME.xsl' you trying to open is in different format than specified with file extension.."


This is strange because I use same custom function to generate files, in most of the cases it work's great, but there are few of them where I have this problem, what could be the glitch?


Oct 1, 2010 at 1:54 PM

This error occurs if, for example, Excel tries to read a file with an extension of .xls that was written using the Excel2007 or HTML writer (ie, not the Excel5 writer).

Oct 1, 2010 at 2:05 PM

I generate file on this way


            ........................add some data...................

            $filename = $name."_".date("Y-m-d_H-i",time()).".xls";
            header('Content-Type: application/vnd.ms-excel');
            header('Content-Disposition: attachment;filename="'.$filename.'"');
            header('Cache-Control: max-age=0');
            $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

and still works for some and not works for other points of call that function :(

Oct 1, 2010 at 2:23 PM

I'm just create an test function with code from example 01simple-download-xls.php and call it from different parts of application and problem still persists for same parts.

Very strange behavior from my POV, that click on one link from diff parts of application call same test function create same excel files, where one doesn't work..I mean excel report this problem...