Double Quotes In Cell Text

Topics: Developer Forum, User Forum
Sep 1, 2010 at 6:04 PM
Edited Sep 7, 2010 at 5:13 PM

I am trying to output an Excel worksheet where some of the cells have double quotes.  On one web server, the worksheet is created fine without any problems.  However, on my production server, any text with double quotes gets truncated at the double quote.

I have a feeling that it is related to ensuring the output is UTF-8, and have tried using the iconv functions, but the documentation is not very detailed about how this should be done.  Can someone provide more detail, or perhaps this is related to a different issue.

As further detail, when I use the function SetCellValueExplicit() to set the cell value and explicitly format it as text, nothing is placed in the cell if the text has double quotes.  The truncation occurs when I set the cell value using just SetCellValue()

I am using phpExcel 1.7.4

The web server that works is running Apache on Windows XP.  The web server that does not work is running IIS.  The issue happens with both double-quotes and dashes that have a space preceding them.  (And perhaps other yet-undiscovered characters). 

I have tried utf8-encode().  This causes the text to no longer get truncated, but the offending character (double-quote, etc) is displayed as some unknown character.



Sep 7, 2010 at 8:33 PM

Just thought that I would post that I solved the issue (with one minor unanswered question).  It was a character encoding issue.  I used the iconv() function as suggested in the documentation. 

The database data being used to populate the spreadsheet had a 'latin_swedish_ci' collation, which corresponds to a 'cp1252' encoding.

The weird thing was that on my local server it did not have an issue, even though the local server database uses the same encodings.  I am not sure if Apache is doing something behind the scenes, because when I changed the code to use iconv(), it still works on both servers.  I would be interested in anybody's thoughts as to why this could be.

Anyhow, one other thing to point out that might be helpful to users is that most of the forum posts here and elsewhere regarding using iconv() or utf8-encode() seem to suggest that most data from Windows would be in a 'ISO-8859-1' encoding.  It should be noted that for data pulled from MySQL, you are more likely to have 'cp1252'.  Since these two encodings are very close, using utf8-encode() eliminated the truncation problem, but not the character conversion problem.