Comments (13)
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.
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.
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.
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.
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.
In Ubuntu 12.04 works, so it seems a problem related to php with Ubuntu 11.10.
from phpexcel.
Thanks for the investigative work... not sure if I should try to do something about this in PHPExcel itself or not
from phpexcel.
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.
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.
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.
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.
@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.
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)
- Is it possible to use php send excel files to client's printer?
- Php Excel fails at load
- Font Style existed but not visible
- exception 'directory'yii\base\ErrorException' with message 'ZipArchive::close(): Failure to create temporary file: No such file
- Syntax error
- An implementation cannot be declared in ambient contexts.
- Setting workbook password does not seem to work at all
- Can't export any excel
- "Excel cannot open the file 'filename.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file. HOT 2
- How can I open the encrypted file?
- Install pathing not working HOT 1
- Do you have a simplified version of PHPExcel?
- Double include PHPExcel_Cell::stringFromColumnIndex function
- PHPExcel_Worksheet_Drawing
- PHP Excel 1.8.2 Loss of precision when writing numeric strings
- Fatal error: Missing function on 1.8.2
- 发现内容部分有错误 HOT 1
- Set document properties with UTF-8 Encoding (for accents)
- read csv with long number data get scientific notation
- export Excel with formulas
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpexcel.