Unreadable content

Topics: Developer Forum
Dec 22, 2008 at 8:46 PM
Edited Dec 22, 2008 at 8:47 PM
I am getting the following error whenever I open a file created with the PHPExcel_Writer_Excel2007 object:

Excel found unreadable content in 'test.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.

Then when I click yes I get this:

Excel was able to open the file by repairing or removing the unreadable content.

Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.

All the content is intact, but when I use Excel5 and change the file extension to .xls everything works and opens with no problems. Any ideas what is causing this?
Developer
Dec 22, 2008 at 9:27 PM
Hmm... we will need to see the file as this is a generic error message. There could be an error in your code, or it could be a bug. Please send the file to erik (at) phpexcel (dot) net.

Which version of PHPExcel are you using? If you are using 1.6.4, can you also try with latest source code?
http://www.codeplex.com/PHPExcel/SourceControl/ListDownloadableCommits.aspx

Developer
Dec 22, 2008 at 10:08 PM
Thanks, I received your test script and I see the problem. You want to output the Excel directly to browser as attachment, and you basically have this:

<?php
    //Create the PHPExcel object
    $objPHPExcel = new PHPExcel();
   
    //Add some data

    //Save Excel 2007 file
    $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);

    // set headers
    header(...);

    $objWriter->save('php://output');
   
    //Echo done
    echo date('H:i:s') . " Done writing file.\r\n";
?>

The problem is with your last echo statement. It is appended to the output stream and becomes part of the Excel file as can be seen if one opens the file in a HEX editor after download. There should be no echo statements in such a script where you send file as attachment for download. Remove it and it will work.
Dec 22, 2008 at 11:58 PM
Thanks for the help, it works perfectly now
Dec 24, 2008 at 10:12 AM
Hie,

what is the difference between
       $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save($file_name);

and  $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
         $objWriter->save('php:/output);

I use the first one, and i have the same error when i open the file via Excel. If i save it in excel5, i haven't got any error.
I try it with the version 1.6.4 and with the patch 23585, but always the same error.


Developer
Dec 24, 2008 at 10:23 AM
It could be a similar problem, we will need to see the file + script. Try to send me the script: erik (at) phpexcel (dot) net.
Developer
Dec 24, 2008 at 11:27 AM
Thanks, I received the files. Could be header problem, but not sure. Looks like you are using 'Content-Type: application/vnd.ms-excel' also for xlsx files. This may give problems.

With xlsx files, the correct header is this

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="My Excel File.xlsx"');

With xls:

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="My Excel File.xls"');
Dec 24, 2008 at 12:15 PM
Edited Dec 24, 2008 at 12:48 PM
For the time being,  I open the file directly from the windows explorateur.
I checked two other exports, and i have the same problem. ok in 2003 but not in 2007.

I made the change for the header, and i have the same problem.

I remove all the display attribute, layout  and i have always the same problem.
I try to open the xml file in the zip but i have the message echec CRC. the file is corrupted.
I think the problem is coming from there

thanks
Developer
Dec 24, 2008 at 2:12 PM
Hmm... do you also get corrupt xlsx file when you save regularly to disk:

$objWriter->save('test.xlsx');

Or is this happening only when you open directly in Internet Explorer?

header(...);
$objWriter->save('php://output');


Dec 30, 2008 at 10:04 PM
I'm having a similar problem except I can't get it to work at all using PHPExcel_Writer_Excel2007. I'm just running the 01simple.xlsx, so it's writing to a file. Everything works fine if I swap in PHPExcel_Writer_Excel5; using PHPExcel_Writer_Excel2007, I get
Excel found unreadable content in 'test.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.

But after clicking "Yes," I get
The Workbook cannot be opened or repaired by Microsoft Excel because it is corrupt.
Any ideas? Thanks,
Kevin
Developer
Dec 30, 2008 at 11:08 PM
You are running 01simple.php with no changes in the script? This is a strange error. However, it could be that you have a defective zip extension. I have not experienced this myself, but others have. Can you perhaps try to run the test on another server?
Dec 30, 2008 at 11:35 PM
Hi Koyama,

Well, I ran it on a linux box and it worked, so that is good news. It would be nice to get it working on my windows box though.. what exactly do you mean a defective zip extension? It's actually a newer version of the zip extension on my windows box which I guess could be causing a problem? Were the others you mentioned able to fix and do you know what they did?

Thanks again!
Developer
Dec 31, 2008 at 12:07 AM
Edited Dec 31, 2008 at 12:09 AM
The only place I have that information is from maarten in this thread. If he does not see this thread I will try to ask him if he has more details.
http://www.codeplex.com/PHPExcel/Thread/View.aspx?ThreadId=37348

With your defective xlsx file, if you change extension to zip, can it be opened as a zip archive? If yes, I think it may not be the zip extension that is the problem, and the problem could be something else. But not sure. Maybe try to compare the good and bad files in hex editor and see if you can see some differences?

Coordinator
Dec 31, 2008 at 5:45 AM
What PHP version are you using on Windows?
Dec 31, 2008 at 4:15 PM
Linux:
PHP Version 5.2.6-3
Zip     enabled
Extension Version     $Id: php_zip.c,v 1.1.2.43 2008/01/18 00:51:38 pajoye Exp $
Zip version     1.8.11
Libzip version     0.8.0-compatible

Windows:
PHP Version 5.2.7
Zip     enabled
Extension Version     $Id: php_zip.c,v 1.1.2.46 2008/11/12 17:50:37 felipe Exp $
Zip version     1.8.11
Libzip version     0.9.0

The file produced on windows is slightly larger.
Jan 5, 2009 at 1:09 PM
Hi,
sorry for the delay. I was on holidays.
Happy new year for everyboydy.

Windows xp SP 2
easyphp  2.0
       php 5.2
       php_zip.dll : 5.2.8.8 . i just installed the last version , i have the same problem than with the 5.2.0

I will try to implement it on the linux box and keep you inform.

thanks
fred
Developer
Jan 7, 2009 at 7:33 PM
So far it looks like this is only happening on Windows. But it is hard to see any pattern.

One more case of defective zip extension. There are examples of defective xlsx files here:
http://www.codeplex.com/PHPExcel/WorkItem/View.aspx?WorkItemId=8840

Here the configuration was this:
windows
easyphp2 with php 5.2.0
zip:
Extension Version     $Id: php_zip.c,v 1.1.2.15 2006/09/24 22:27:57 pajoye Exp $
Zip version     2.0.0
Libzip version     0.7.1

Defective sample files provided by mmiat from thread #43553





Jan 8, 2009 at 8:50 AM
I have also the problem on linux

PHP Version 5.2.6

zip

Zip enabled
Extension Version $Id: php_zip.c,v 1.1.2.43 2008/01/18 00:51:38 pajoye Exp $
Zip version 1.8.11
Libzip version 0.8.0-compatible

Coordinator
Jan 8, 2009 at 12:22 PM
http://pecl.php.net/bugs/bug.php?id=9278 provides some insights. Seems like a fauly SAPI module in the web server?
Jan 20, 2009 at 9:13 PM
I had the same problem.

The php_zip.dll extension tried to write in binary mode, but it cannot, so it wrote 0D0A instead of 0A.

The files were larger, and CRC errors all the time.

Further information: http://bugs.php.net/bug.php?id=39506
The dll which was good for me were here: http://snaps.php.net/win32/php5.2-win32-latest.zip
Developer
Jan 21, 2009 at 6:58 AM
@tamaskoczka: Thank you for posting! Great help!


Jan 22, 2009 at 1:53 PM
Hi

I installed latest php release 5.2.8 to windows xp machine using wamp-server. After update, every file even the examples were corrupted after save. I checked new and old files with HEX-editor and there was lot of difference. Old file seems to be a little smaller. Anyway after copying zip-library (php_zip.dll 5.2.8.  -- >  php_zip.dll 5.2.7.7) from older release everything seems to be fine again... Weird...

-Jarkko 
Developer
Jan 22, 2009 at 2:35 PM
Am I understanding this right:
  • There was first a bug with php_zip.dll, then it got fixed and bug was closed. Everything ok.
  • Bug has now reappeared in newest distribution and there is no open bug report? Hence we are forced to downgrade php_zip.dll to get things to work on Windows?

Jan 22, 2009 at 4:57 PM
Edited Jan 22, 2009 at 5:18 PM
In my case yes!

Here's my story:
First I thought there were some problems with my pear spreadsheet_excel_writer but no... I uninstalled everything. Php, apache and all wamp-stuff (okay, I didn't reinstall OS and some system variables) and made blank install with newest wamp-server which includes 5.2.8 PHP. Then after setting php.ini's etc I started testing code again. My own system wasn't workin, so I tested example files. They were working neither. After downloading php 5.2.7.7. and just copy-pasting php_zip.dll from older php-release things were allright again...

-Jarkko
Jan 22, 2009 at 6:04 PM
koyama: yes, i think it's absolutely a zip_php.dll bug, and a mistake from the php guys. if you try to compress the bytes #00 - #FF with the new zip_php.dll (in my case it came with the php version 5.2.5), you will get the test zip file corrupted. but the phpexcel works great after the dll change :)   (if you can of course, it's lucky, the servers at webhostings are usually run on linux :))

ps: sorry for my english
Developer
Jan 22, 2009 at 6:16 PM
JLoima and tamaskoczka, thank you both for your explanations and instructions how to solve this. This will help others. Things are starting to make sense now. This was really a mystery bug!

Sounds like we will have to examine whether a bug needs to be filed for this.

Coordinator
Jan 23, 2009 at 7:47 AM
Might also be worth putting something in the FAQ
Coordinator
Jan 23, 2009 at 8:17 AM
Will add this to FAQ. Also, I'll file a bug on bugs.php.net for this.
Coordinator
Jan 23, 2009 at 8:27 AM
Bug already fixed in PHP CVS: http://bugs.php.net/bug.php?id=46985
Jan 28, 2009 at 10:28 AM
Edited Jan 28, 2009 at 10:29 AM
Hello.

Guys, unfortunately it's not working with any version on php in my case.

When I save file directly to hdd, file is ok,
but, file saved from browser don't want to open in Excel.

There is difference between those two files, bad one is 2 bytes larger than good one.

You can see it here: http://antczak.org/bug/

When I unzip bad file, and zip it again with 7zip, Excel can read it.

What do You think about this?

Thanks for help.
Regards.
Developer
Jan 28, 2009 at 11:18 AM
This sounds very strange! The strange thing is that the two files are different. That kind of rules out that it is the php_zip.dll bug the others are describing.

Just for double checking, can you try to run your script with latest source and see if you get same error?
http://www.codeplex.com/PHPExcel/SourceControl/ListDownloadableCommits.aspx

Jan 28, 2009 at 11:51 AM
Upgrading to nightly version didn't help.
So it probably PHP bug, what do You think about this?
Developer
Jan 28, 2009 at 12:10 PM
Can you try to run this:

<?php
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="myfile.xlsx"');
header('Cache-Control: max-age=0');

echo file_get_contents('good.xlsx');
?>

Basically, we are here just sending the good file, and then seeing what comes out at the client's browser. This is to see if it is the browser that is somehow messing with the file.

Jan 28, 2009 at 12:23 PM
Unfortunately new saved file is corrupted.

What do You think can cause this?
Developer
Jan 28, 2009 at 12:54 PM
  1. Can you upload the new file myfile.xlsx for inspection?
  2. What browser are you using? Can you try with some different browsers?

Jan 28, 2009 at 1:04 PM
I've checked this in three browsers, result is same.
Saved version of good.xlsx You can find here: http://antczak.org/bug/.
Developer
Jan 28, 2009 at 1:26 PM
Can you try to run this again:

<?php
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="myfile.xlsx"');
header('Cache-Control: max-age=0');

echo file_get_contents('good.xlsx');
?>

But this time, remove any newline or carriage returns after the closing ?> tag. There must not be any.

Jan 28, 2009 at 1:26 PM
Edited Jan 28, 2009 at 1:36 PM
korro: There are newline characters at the end of your files (myfile_*.xlsx files are exactly the same).

I think maybe they are in the original php file, try this:
echo file_get_contents('good.xlsx');
exit;
?>


The "exit;" command will prevent the php engine from writing anything after the file contents...

The second option is: the webserver writes the extra characters. In this case, we have to know the webserver's parameters (name, version, loaded modules, etc)...

Jan 28, 2009 at 2:08 PM
You're right, after adding exit; just after line witch send data everything is ok.
Thanks guys, and sorry for rookie mistake.
Feb 17, 2009 at 12:34 PM
I try everything and i have always the same problem. As suggest from maartenba, I download the version of PHP and still have the same problem.
I install the last version of pkzip on the linux box and nothing change.
Everything is ok in 2003 but always the same msg for 2007
Developer
Feb 17, 2009 at 4:57 PM
@leursfre: Is this happening also when you create a blank workbook?

Feb 18, 2009 at 2:09 PM
i try 3 of your exemples and it works fine.
I try on an other pc and now it's a little bit different. I have always the message : excell found unreable content but
If you click yes, i have got something now but all the function subtotal  have disapeared and the column with if also.
and i have the message : Removed record : formula from /xl/worksheets/sheet1.xml part

Developer
Feb 18, 2009 at 9:20 PM
@leursfre: "Excel found unreadable content" is a generic message, and there could be many reasons for this error. I think your case does not have anything to do with zip extension. You would not get that message about "Removed record". Can you send me the file (erik at phpexcel dot net) so we can investigate?

Feb 19, 2009 at 11:38 AM
I think i had two problems. Because before i put the last version of php and zip, i cannot open the file. and can't dezipp the xslx file manually
Now i can dezipp the file manually and open the file in excell. but fonction have desappeared.
Developer
Feb 19, 2009 at 11:50 AM
@leursfre: File received. It looks like the error comes from using semicolon “;” as argument separator in formulas when one should use in fact use comma “,”
Internally, Excel always stores formulas using “,” as argument separator no matter whether you save from e.g. German or English Excel version.


Feb 19, 2009 at 1:32 PM
Edited Feb 19, 2009 at 1:33 PM
effectively. If i change the ';' by ','. It works in 2003 and 2007. probably, the conversion is managed  in the writer for 2003
It's strange, because i have got a french and an english version of excel. In excel, for all the formula, you write them with ';'. But effectively, if you dezipp a file the functions are written with a ','.
I thinks, it's coming for the language you use in windows. Because for us, the decimal separator is ',' so it couldn't be also the separator for the argument of a function.
it's the same for the format of a numeric value. Always put '.' as decimal separator even if it's ',' in your language ( excel).
probably, it could be usefull to add something about that in your documentation.

thanks
Developer
Feb 20, 2009 at 7:14 AM
@leursfre: Will look at documentation and make sure that things will be clear in next release.

Feb 24, 2009 at 2:53 AM
Edited Feb 24, 2009 at 2:58 AM
Hi,
I'm getting the same "found unreadable content" error when just opening then immediately saving an xlsx file for an invoice template, however opening and saving the xlsx file generated by 05featuredemo.php works fine. It also outputs OK in HTML format. I tried upgrading to the lastest code from the repo and it still doesn't work, however I now get this notice 32 times:
Notice: Array to string conversion in /home/shaun/www/herecomethelizards/htdocs/excel_test/Classes/PHPExcel/Cell.php on line 245
The code I'm using is:
<?php
error_reporting(E_ALL);

set_include_path(get_include_path() . PATH_SEPARATOR . './Classes/');
include 'PHPExcel/IOFactory.php';

$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("invoice.xlsx");

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('test.xlsx');
?>
With this file which outputs this file. I'm running PHP 5.2.8 on FreeBSD.

Any idea what the problem is? I thought maybe it was some unsupported feature in the input file, but it's a very basic spreadsheet so that doesn't seem very likely.
Developer
Feb 24, 2009 at 5:13 AM
@RiskyShift: Will check this!
Developer
Feb 24, 2009 at 6:27 AM
@RiskyShift:

1. Issue with notices verified. A work item has been created for this:
http://www.codeplex.com/PHPExcel/WorkItem/View.aspx?WorkItemId=9337

2. Note, if you merge, say, C15 through H15, then you would normally refer to the merged cell as just C15 and not C15:H15 like in your sheet.

3. As for the problem you are describing with "Unreadable content" after a plain save, I have not been able to reproduce this. Which Excel file is this happening with? Can you upload an example somewhere?

Feb 24, 2009 at 8:39 AM
Thanks for the info about the merged cells, I didn't make the sheet, I'm just trying to generate them automatically for web orders for someone, but I'll let him know.

I'm getting the problem with the file I linked to (http://herecomethelizards.co.uk/excel_test/invoice.xlsx) with that exact code. If I use the same code with another xlsx file (e.g. http://herecomethelizards.co.uk/excel_test/1.xlsx) though it works fine.
Developer
Feb 24, 2009 at 12:46 PM
@RiskyShift:

There appears to be a bug with PHPExcel's calculation engine when one is adding a string and a number.

I have posted this in the issue tracker asking for a solution:
http://www.codeplex.com/PHPExcel/WorkItem/View.aspx?WorkItemId=9339

Meanwhile you can solve this by replacing the formula in cell J44 in the first sheet:

=IF(J42=0,"",IF(J42<30.01,5,0))

with this

=IF(J42=0,0,IF(J42<30.01,5,0))

Depending on your needs, if you run into more of theses problems, you may try to disable precalculation of formulas. [ $objWriter->setPreCalculateFormulas(false) ]
Feb 24, 2009 at 8:09 PM
Thanks, that fixed it.
Apr 4, 2009 at 6:41 PM
This is fixed in PHP 5.2.9
So if you have this problem : upgrade to / install PHP 5.2.9.x
or just download and use this dll instead of your "php_zip.dll" file

http://www.netsaz.com/myweblib/php_zip.dll_v5.2.9.9/php_zip.dll
Developer
Apr 5, 2009 at 9:10 AM
@imami: Good to know! Updated FAQ.

Jul 1, 2011 at 7:26 AM

Hello All,

Same problem : Excel found unreadable content in 'text.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.

I'm using this phpexcel version 1.7.6 with LAMP environment having php version 5.2.17 and php_zip version 1.8.11.

I'm writing xlsx document with around 30 sheets. I get the proper excel file with one recovered sheet and If I regenerate the file with some sheet data skipped, it works fine. I've also noticed that the there is no sheet data at fault as I've checked this with alternate sheets as well. Open Office Reports no such error in same scenario whereas MS Office is having some problem in handling large data.

kindly assist and add your valuable inputs on it.

Manish

 

 

 

Jan 19, 2012 at 9:23 AM

I had the same problem on Win7 64bit: correct creation of the xlsx, but when outputting it to the browser, the file gets corrupted (a line break is added before the start of the document). 

I've finally solved it by upgrading my PHP version (from 5.3.6 to 5.3.9) AND restarting my computer (I wish I had done that last step a few hours earlier!!).

Just restarting Apache was not good enough.

Hopefully this helps anyone.

 

Kind regards,
<Johey> 

Jan 13, 2014 at 2:06 PM
Just my 2c:
I had this issue too and in my case it was caused by writing a special latin1 character "ë" into the description:
$description = 'Geëxporteerd';
$objPHPExcel->getProperties()->setDescription($description);

PHPExcel doesn't check the encoding of strings being set. My site is in latin1 encoding and PHPExcel expects UTF-8.

So the solution turned out to be:
$objPHPExcel->getProperties()->setDescription(mb_convert_encoding($description, 'UTF-8'));
Dec 3, 2014 at 11:35 AM
Hi

My code dynamic export excel. My excel in data and charts. İ m not problem libre office, everything see good. But MS 2010 error Unreadable content.
My code is here.
    $this->load->library('excel');

    $this->excel->setActiveSheetIndex(0);


    $char = "A";
    foreach($headers as $header):
        $this->excel->getActiveSheet()->setCellValue($char.'9', $header);
        $this->excel->getActiveSheet()->getColumnDimension($char)->setWidth(20);
        $char_old = $char;
        $char++;
    endforeach;
    $this->excel->getActiveSheet()->setTitle($worksheet_name);
    $this->excel->getActiveSheet()->setCellValue('A5', $worksheet_name);
    $this->excel->getActiveSheet()->getStyle('A5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $this->excel->getActiveSheet()->getStyle('A5')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    $this->excel->getActiveSheet()->mergeCells('A5:'.$char_old.'8');
    //$this->excel->getActiveSheet()->mergeCells('A1:M1');
    $header = 'a9:'.$char_old.'9';
    $this->excel->getActiveSheet()->getStyle($header)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF0000');

    $objDrawing = new PHPExcel_Worksheet_Drawing();
    $objDrawing->setName('EBA');
    $objDrawing->setDescription('Logo');
    $logo = './public/assets/img/eba-new.png'; // Provide path to your logo file
    $objDrawing->setPath($logo);
    //$objDrawing->setOffsetX(8);    // setOffsetX works properly
    //$objDrawing->setOffsetY(30);  //setOffsetY has no effect
    $objDrawing->setCoordinates('A1');
    $objDrawing->setHeight(80); // logo height
    $objDrawing->setWorksheet($this->excel->getActiveSheet());

    $objDrawing = new PHPExcel_Worksheet_Drawing();
    $objDrawing->setName('İnfoteks');
    $objDrawing->setDescription('Logo1');
    $logo = './public/assets/img/infoteks.png'; // Provide path to your logo file
    $objDrawing->setPath($logo);
    //$objDrawing->setOffsetX(8);    // setOffsetX works properly
    //$objDrawing->setOffsetY(30);  //setOffsetY has no effect
    $objDrawing->setCoordinates($char_old.'3');
    $objDrawing->setHeight(50); // logo height
    $objDrawing->setWorksheet($this->excel->getActiveSheet());

    $this->excel->getActiveSheet()->fromArray($result_array, ' ', 'A10');

    if($export_page == "app_report"){
            $dataSeriesLabels1 = array(
                new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 10),   
            );$xAxisTickValues1 = array(
                new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$'.$i, NULL, 40),  
            );$dataSeriesValues1 = array(
                new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$'.$i, NULL, 40),
            );
            //echo "<pre>";
            //var_dump($dataSeriesValues1);
            $series1 = new PHPExcel_Chart_DataSeries(
                PHPExcel_Chart_DataSeries::TYPE_BARCHART,               
                PHPExcel_Chart_DataSeries::GROUPING_STACKED,                                                   
                range(0, count($dataSeriesValues1)-1),                  
                $dataSeriesLabels1,                                     
                $xAxisTickValues1,                                      
                $dataSeriesValues1                                      
            );

            $layout1 = new PHPExcel_Chart_Layout();
            //$layout1->setShowVal(TRUE);
            $layout1->setShowPercent(TRUE);

            $plotArea1 = new PHPExcel_Chart_PlotArea($layout1, array($series1));                
            $legend1 = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
            $title1 = new PHPExcel_Chart_Title('Toplam Çalışma');

            $chart1 = new PHPExcel_Chart(
                'chart1',       
                $title1,        
                $legend1,       
                $plotArea1,     
                true,           
                0,              
                NULL,           
                NULL            
            );

            $chart1->setTopLeftPosition($char.'2');
            $chart1->setBottomRightPosition('Z30');

            //$objWorksheet->addChart($chart1);
            $this->excel->getActiveSheet()->addChart($chart1);

            $dataSeriesLabels1 = array(
                new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$9', NULL, 10),   
            );$xAxisTickValues1 = array(
                new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$10:$A$'.$i, NULL, 40),  
            );$dataSeriesValues1 = array(
                new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$10:$D$'.$i, NULL, 40),
            );

            $series1 = new PHPExcel_Chart_DataSeries(
                PHPExcel_Chart_DataSeries::TYPE_BARCHART,               
                NULL,                                
                range(0, count($dataSeriesValues1)-1),                  
                $dataSeriesLabels1,                                     
                $xAxisTickValues1,                                      
                $dataSeriesValues1                                      
            );

            $layout1 = new PHPExcel_Chart_Layout();
            $layout1->setShowVal(TRUE);
            $layout1->setShowPercent(TRUE);

            $plotArea1 = new PHPExcel_Chart_PlotArea($layout1, array($series1));                
            $legend1 = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
            $title1 = new PHPExcel_Chart_Title('Toplam Çalışma');

            $chart1 = new PHPExcel_Chart(
                'chart1',       
                $title1,        
                $legend1,       
                $plotArea1,     
                true,           
                1,              
                NULL,           
                NULL            
            );

            $chart1->setTopLeftPosition($char.'30');
            $chart1->setBottomRightPosition('Z60');

            //$objWorksheet->addChart($chart1);
            $this->excel->getActiveSheet()->addChart($chart1);

    }
header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="'.$export_page.'.xls"'); 
    header('Cache-Control: max-age=0'); 



    $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007');  
    $objWriter->setIncludeCharts(TRUE);
    $objWriter->save('php://output');
Coordinator
Dec 3, 2014 at 11:56 AM
Open the file in a text editor.

Look for any leading/trailing whitespace characters at the beginning or end of the file; look for a BOM header at the beginning of the file; look for any plaintext PHP error messages or any HTML markup in the file....

if your script is generating any output at all, it will corrupt an Excel file saved to php://output