PHPExcel_IOFactory unreadable cells with mixed font properties

Topics: Developer Forum
Oct 15, 2014 at 1:47 PM
I try to read an Excel5 file (.xls) containing cells with a complex layout.
The cell content pattern is "text1 text2" where text1 has a different text color than text2, or text1 has striketrough while text2 has not. text1 and text2 are separated by a single space.
When I load the sheet using PHPExcel_IOFactory and check the contents with:

$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);

I found out that it works fine for most cells, but cells with the mixed font properties as described above always give:
'Q' => null
suggesting that it is an empty cell, while it is not. It just contains "text1 text2" but special font properties apply only to one part.
Is there a solution to this problem?

I am using PHPExcel 1.8.0.
php 5.5.16
OS: Fedora 19
Oct 15, 2014 at 3:38 PM
Edited Oct 15, 2014 at 3:39 PM
Cells of this type contain a Rich Text Object in PHPExcel. When you use getValue() or similar to retrieve that cell, you should get a PHPExcel_RichText object back rather than a simple PHP scalar. Take a look at the API docs to see what methods are available for PHPExcel_RichText objects.
Oct 16, 2014 at 3:06 PM
Hi Mark,
Thanks for your reply. I have tried your Rich Text Object Solution, but it persisted in returning nothing else than "null".
I have copied and pasted a part of the Excel sheet with the "difficult" cells into a new empty Excel file and saved it with a different name using Microsoft Excel.
This new file returns exactly the desired values, both with the Rich Text Method and with the original toArray method. There is no problem at all with this new file.

My conclusion is that there is something wrong with the original xls file, although I have no clue what it can be. It is not really corrupt because it can be opened and edited easily with Microsoft Excel. So Microsoft Excel (both Excel2003 on WinXP and Excel2010 on Win7) is obviously able to read the "difficult" cells correctly.