Danish Characters in generated Excel document

Topics: User Forum
Sep 6, 2009 at 12:24 PM

Hi, I've been working round with the great (!!) PHPExcel Class, but I cannot get it to print the danish characters æ-ø-å. Even just modifying the "00simple.php" example from the Tests directory to print some danish characters does not work. Once it meets the first danish character it stops printing further to the current cell. Does anyone know if there's a way to work around this? Thanks!

Developer
Sep 6, 2009 at 12:42 PM

Just type the Danish characters directly, but make sure you save your PHP-script as UTF-8 (without BOM). Example:

$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Hello æøå');

Good text editors can save as UTF-8 without BOM. For example Notepad++ can. Look at this thread to see some details:

http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=52427

I will see if I can modify 01simple.php to show how to insert various special characters.

Sep 6, 2009 at 2:50 PM

Hi Koyama, thanks a lot for your reply. I figured out that the Eclipse editor on my Mac saved my files using the wrong encoding. However, it is still not working. Unfortunately, my web hosting (at present) does not have the PHP extension php_zip and php_xml enabled. Because of this I've been trying just to generate Excel5 files, and that worked nicely, but without the æ-ø-å letters. Is the php_zip and php_xml extensions necessary for the various special characters? As far as I can understand from the thread you refer to, it is. Is that right?

Developer
Sep 6, 2009 at 3:30 PM
Edited Sep 6, 2009 at 3:36 PM

>> Unfortunately, my web hosting (at present) does not have the PHP extension php_zip
>> and php_xml enabled. Becauseof this I've been trying just to generate Excel5 files, and
>> that worked nicely, but without the æ-ø-å letters.


I am quite convinced that it is an encoding problem. The way I usually check the encoding for files created by some text editor.

  1. Create a plain text file in your editor containing some text: "Hello æøå" save it as test.txt
  2. Open the file in Firefox
  3. Choose View > Character Encoding > UTF-8
  4. Inspect what you see on the screen.

In step 4, it should look like this:


If you instead see something like this, then the editor is not saving as UTF-8

 

 

>> Is the php_zip and php_xml extensions necessary for the various special characters?

No, those extension are only necessary for reading/writing xlsx files with Excel2007 reader/writer. However, you will need either iconv or mbstring enabled to read/write xls files containing non-ASCII characters with Excel5 reader/writer. Most hosts (even the cheap ones) have both of those enabled, so I don't think this is the problem, but check phpinfo() anyway to be sure.

Sep 7, 2009 at 5:18 PM

Hi Koyama. Thanks. You were absolutely right. It was an encoding problem. Thanks to your trick with viewing the files in Firefox I found out that the encoding was still wrong. Now it works. Thanks :-)