Excel graphic problem

Topics: Developer Forum, User Forum
Oct 22, 2012 at 5:23 PM
Edited Oct 22, 2012 at 8:17 PM


I have a problem when I open an excel file with a graphic created with excel, then modify it and finally save it to disk.

When I try to open de updated file using excel, the file is short and the graphics are not comleted, the doesn't have the background, the border and so on. I got the error: part of the file cannot be read Do ypu wish and repair this file?

Is necesary to say that all the text into the file is OK but the original graphic is not the same. I have not changed by program the original graphic.

Simple excel files without graphics works right. I have check the Test/32chartreadwrite.php example with the same results when I update a cell, I think is a bug into de code.

The code I am using is the following:

require_once 'Classes/PHPExcel/IOFactory.php';
require_once 'Classes/PHPExcel.php';

$inputFileType = 'Excel2007';
$inputFileName = 'File.xlsx';
$generatedFile = 'zzz.xlsx';

try {

    // Create a new Reader of the type defined in $inputFileType
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);

    //  Load $inputFileName to a PHPExcel Object
    $objPHPExcel = $objReader->load($inputFileName);

    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->getActiveSheet()->setCellValue('C13', '2');

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $inputFileType);
    if (file_exists('excel/' . $generatedFile )) {
        unlink('excel/' . $generatedFile);

} catch (Exception $e) {
    die('Error on file: ' . $e->getMessage());

Any Ideas? I need this urgent,

Thank you in advance.

Oct 23, 2012 at 10:42 PM

What version of PHPExcel are you using?

And simply telling me that there is a bug somewhere in nearly 100,000 lines of code doesn't really help me narrow down any problem at all. Perhaps uploading the two files might help me a little bit.

Oct 24, 2012 at 12:32 AM
Edited Oct 24, 2012 at 12:35 AM


I am using the latest version 1.7.8.

How Do I send you my excel File? you can use the code I copied above.


Oct 24, 2012 at 7:40 AM

Files can be attached to Work Item http://phpexcel.codeplex.com/workitem/10749?ProjectName=phpexcel

Oct 26, 2012 at 6:10 PM

I have upload 3 files:


1 I Have.png

2 I Got.png


Thank you

Oct 26, 2012 at 9:36 PM
Edited Oct 26, 2012 at 11:40 PM

Is that the xlsx file written by PHPExcel, or the file you're loading into PHPExcel? I'm asuming that it's your template; but it complains about the protection when I load it in MS Excel 2010. PHPExcel has a similar problem reading the protection, and writes the workbook with an empty password which gives validation errors when tested under the OpenXML SDK Productivity Tool, related to the protected ranges.


Looking at your template: MS Excel itself displays the message: "The data range is too complex to be displayed" when I try to display the data source, and I thought at first that it was probably a bit too complex for PHPExcel to handle; but subsequent investigation has revealed only a few discrepancies.

I've modified the chart writer code to handle references to cells where data isn't pre-populated, and made a minor tweak to the order in which XML elements are written: I'll upload these fixes to github later tonight.

Oct 26, 2012 at 11:50 PM

Thank you very much! I hope this solves the problem.

Oct 26, 2012 at 11:59 PM
Edited Oct 27, 2012 at 12:00 AM

It won't solve all the problems: there's something in the cell data that is still throwing up an error, I haven't been able to track that down yet; although it does seem to load up in MS Excel once the Excel loader has "fixed" that. I'm currently fixing the validation for the empty protected cells password.


There's also one chart bug in the second chart: it isn't showing the legend values correctly - I still need to identify whay that's not correct.


It's also worth noting that not all chart stylings are yet supported, so the chart background colouring and the text stylings aren't identical because they simply default. These will come in time, but getting the basic chart features such as data display correct are more important at this point in the development.


Oct 27, 2012 at 12:40 AM

Of course, I will continue attentive to your comment. Thank you again.