Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unescaped Characters in Cell Stop Row Processing PHPExcel

This is a follow-on question from this one: Algorithm to dynamically merge arrays

There are unescaped characters in some of the cells in the spreadsheet. I try to escape them with addslashes() but phpexcel seems to ignore this and stop processing the rest of the rows. I get this error in the logs:

 PHP Warning:  Unexpected character in input:  '\' (ASCII=92) state=1

I've looked through the API; I haven't seen any text formatting methods that I can use. (Please correct me if I'm wrong)

Your help is appreciated.

like image 904
Mina Avatar asked Dec 23 '11 07:12

Mina


1 Answers

From the PHP documenation:

"It is necessary to use UTF-8 encoding for all texts in PHPExcel. If the script uses different encoding then it is possible to convert the texts with PHP's iconv() function."

Escaping the characters won't do anything, as the characters that are not valid UTF8 characters, will stay invalid.

Although you could do character set conversion when you pass the data to PHPExcel, I'd instead strongly recommend switching your whole project to UTF8 as dealing with multiple character sets in one project is not a good problem to have.

like image 198
Danack Avatar answered Nov 16 '22 00:11

Danack