Giter Club home page Giter Club logo

Comments (13)

gianlucagiacometti avatar gianlucagiacometti commented on May 9, 2024 1

OK I think I found the problem!
All was caused by a newline somehow set by header() before calling the IOFactory. The resulting file has a starting newline causing excel not to recognise the file format.
There's no issue in PHPExcel about that because if you skip headers and save the file it has no newline at the beginning.
The solution is to add a ob_clean(); after the header lines just before calling IOFactory:

header('Content-Disposition: attachment;filename="list.xlsx"');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Cache-Control: max-age=0');
ob_clean();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');

from phpexcel.

MarkBaker avatar MarkBaker commented on May 9, 2024

If your code is identical, and the version of PHPExcel is identical, then there's something different in your hosting configuration. What do you mean by encoding though? Do you mean character set?

from phpexcel.

Nicolas400 avatar Nicolas400 commented on May 9, 2024

Yes, in the hosting that returns bad characters I was forced to add some lines in php to the main program, header(... charset= "utf8").
I have no idea which character set is running on the hosting, is there any test that I can run ?
I'm running this library as an extension within yii framework.

Best Regards

from phpexcel.

MarkBaker avatar MarkBaker commented on May 9, 2024

header charset has no effect whatsoever on the content of the file generated by PHPExcel. There could be differences in the configuration of PHP between the two machines: do a phpinfo for the two servers, and look for the differences

from phpexcel.

gianlucagiacometti avatar gianlucagiacometti commented on May 9, 2024

I have the same problem. If I output xls (Excel5) the file is open but in a messy format, xlsx (Excel2007) says format not valid. Tried with phpExcel 1.7.7. and the last 1.7.8 RC downloaded today.
The one working is on Deb 6, the one not is on Ubuntu 11.10, both with php 5.3. I guess is php libraries (now php_zip is embedded in php but may be buggy).
I will investrigate more in the following days, also with Ubuntu 12.04 to chech if something changes.

from phpexcel.

gianlucagiacometti avatar gianlucagiacometti commented on May 9, 2024

In Ubuntu 12.04 works, so it seems a problem related to php with Ubuntu 11.10.

from phpexcel.

MarkBaker avatar MarkBaker commented on May 9, 2024

Thanks for the investigative work... not sure if I should try to do something about this in PHPExcel itself or not

from phpexcel.

MarkBaker avatar MarkBaker commented on May 9, 2024

Can you hash your script file on but versions of Ubuntu just to confirm that it is actually identical, and that one version doesn't have a spurious white space somewher?

from phpexcel.

gianlucagiacometti avatar gianlucagiacometti commented on May 9, 2024

I tryed in another Ubuntu 12.04 identical to my last new one (I just setup a new server for a new service) and the problem re-appeared...
The only difference between the two is the presence of an external firewall (without works), but no evidence it depends on that.
I'm sure it does not depend on PHPExcel itself.
The best thing to do in my opinion is to tell people to add "ob_clean();" in the readme/manual.
Ehmmm.. Never hashed anything so far, if you tell me how to do that I will (blush)

from phpexcel.

MarkBaker avatar MarkBaker commented on May 9, 2024

Linux has an md5sum that will generate an md5 hash value for a specified filename. e.g.:

md5sum myTestFile.xls

gives

36fab1926423d8acb9884fe4c2d8e913 myTestFile.xls

from phpexcel.

gianlucagiacometti avatar gianlucagiacometti commented on May 9, 2024

SERVER 1:

7fb71b65fb693b336b0845fdafedf55c export_chiese.php

a12ba0e5bfd258ee2be51e02b9b3723a export_palazzi.php

SERVER 2:

7fb71b65fb693b336b0845fdafedf55c export_chiese.php

a12ba0e5bfd258ee2be51e02b9b3723a export_palazzi.php

seems exactly the same
G

from phpexcel.

ezzatifa3 avatar ezzatifa3 commented on May 9, 2024

@gianlucagiacometti tq so much for the ob_clean(); solution!! I have been looking everywhere for the right solution. Finally, i got it working now. Thanks!

from phpexcel.

davidvegacl avatar davidvegacl commented on May 9, 2024

Hours of debugging and finally the problem was a newline at the begining of a long controller file. Thanks for the solution @gianlucagiacometti

from phpexcel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.