Error with reader and merged cells

Sep 18, 2012 at 10:31 AM
Edited Sep 18, 2012 at 10:31 AM

Hi all,

i'm having a big and strange problem with reader and excel file with merged cells, created by phpexcel.

In details: i create a file with phpexcel, and it has some merged cells inside (all ok)

If i read this file with phpexcel, all is ok and merged cells are read correctly.

If i edit this file (even only opening and saving it) with excel, something changes (nothig that can be seen in the file..) and i'm no more able to read it with phpexcel, because an error on merge cells is given

Fatal error: Uncaught exception 'Exception' with message 'Merge must be set on a range of cells.' in [...]\Includes\Classes\PHPExcel\PHPExcel\Worksheet.php:1656 Stack trace: #0 [...]\Includes\Classes\PHPExcel\PHPExcel\Reader\Excel2007.php(1105): PHPExcel_Worksheet->mergeCells('U35') #1 [...]\index.php(438): PHPExcel_Reader_Excel2007->load('./[...]') #2 {main} thrown in [...]\Includes\Classes\PHPExcel\PHPExcel\Worksheet.php on line 1656

so, it seems that for READING the file, phpexcel is calling the "mergeCells" on single cells (why?), and something is not working.

What kind of problem is this?

the error is given even if i save in excel 2003 format, so i don't think it can depend on excel 2010 differences with excel 2007.

Mark please save me :)

Coordinator
Sep 18, 2012 at 11:10 AM

I'll need to try and recreate this. Do you actually have any example code that I can use as a basis?

Sep 18, 2012 at 12:30 PM

the problem is given (obvious if you see the class code) only when setReadDataOnly is not set to TRUE.

I'm using this part only to read the "merged cells array" (if you remember, we already talked about this)

Now, i've commented the line in worksheet.php that throws the exception, and in this way everything is working, but i can see that it's trying to merge A LOT of cells.

I've created a little test script and a test xlsx file (that is the one created me problems, but without contents..)

Here they are

https://www.dropbox.com/s/673gopo6g5hk7uo/TestMerge.zip

Thank you Mark!

Coordinator
Sep 19, 2012 at 11:36 PM

Ridiculous of Excel to allow a single cell to be set as a merge range, it seems totally ridiculous.

Readers fixed to discard meaningless single-cell merges in the develop branch on github

Sep 20, 2012 at 8:17 AM

Sorry Mark, i haven't understood.

Is there a problem in my code? (i mean the code generated the file, not the stupid code of the test script)

Why the problem is rising only after opening and saving the file with excel?

Thanks and sorry if i did any mistake :)

Sep 20, 2012 at 8:27 AM
Edited Sep 20, 2012 at 8:32 AM

lol, i'm SO noob, i'm not able to download files from github :)

any help? :P

(Edit: Ok, downloaded it all, and it works! thanks mark!)

 

(next test script will be excel 2010 compatibility for "setReadDataOnly :P)

Coordinator
Sep 20, 2012 at 9:55 AM

I don't know how the problem originated, because PHPExcel will only set merges if you explicitly tell it to set merges, and won't allow you to merge a single cell, only a range of cells. I wasn't able to replicate any situation that created single cell merge ranges other than using MS Excel itself, and even then I had to tell MS Excel to set those merge ranges on single cells.