Excel Writer Charset eg UTF-8

Jul 12, 2007 at 2:40 PM

Is there any possibility to save the Excel Files in different Charsets? Because I have all data stored as UTF-8 and the tool creates a Excel-File the file will be written in the standard charset definition. This implies that special chars are not recognized in the excel, and displayed as unknown chars. Can anybody help me?
Jul 13, 2007 at 6:53 AM
Zeradun, Excel2007 should support UTF8!
A possibility to enforce this via PHP is 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.

Excel5 writer probably does not support UTF8 encoding, which means you will need to fall back to single byte characters for that output purpose...
Aug 17, 2007 at 3:37 PM

Thanks. It worked fine with UTF8. In Excel 5.

$xfieldContent = $field->getForm()->getCurrentContent();
$xfieldContent = utf8_decode($xfieldContent);
$excelObj->getActiveSheet()->setCellValue($fieldName, $xfieldContent);

Dec 10, 2007 at 7:48 AM
hi all,

PHPExcel is really powerful.I have a problem and i need your help.i just want to insert chinese character to excel file.so how can i achive there.how some one can tell me where i can change the charset of the file generated by PHPExcel.
Mar 5, 2009 at 8:10 AM
The XML files generated by PHPExcel have as header:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

Seems to me that PHPExcel then needs to ensure the files are actually encoded as UTF-8.

When I save the spreadsheet with the Excel2007 writer, Excel then complains that it can't open the file, asking to restore it. When I unzip the .xlsx file, open all the XML file with Editplus and set the encoding to UTF-8, then rezip, it opens without a problem.

I found that altering PHPExcel\Writer\Excel2007.php so that every call to addFromString is changed so that it utf8_encode-s the variable works too, but I don't know if that only works for my input.
Mar 5, 2009 at 10:59 PM
@Jbwdevries: PHPExcel_Writer_Excel2007 should be working with UTF-8 directly out of the box. Make sure you're feeding PHPExcel with UTF-8 encoded strings. Perhaps you are using some other encoding?

Mar 6, 2009 at 6:39 AM
Hmm, I thought I had the source files (which I loaded with the CSV reader) in UTF-8 encoding, but it turns out it didn't.

Regardless of that; my point was somewhat that the suggestion offered by zeradun (encoding/decoding each field) is not really feasible. Can it hurt to leave the utf8_encode in the writer? It worked for my test cases (both UTF-8 source and another, ANSI I think), but I'm not sure if it'll clash with other encodings.
Mar 7, 2009 at 12:25 AM
@Jbwdevries: I recommend not to alter the reader/writer. If you leave the utf8_encode in the writer you will not get correct output if you have characters outside the ASCII range. PHPExcel operates strictly with UTF-8.

Mar 7, 2009 at 8:48 AM
I'm getting some wonky results now indeed. Alright, I'll leave it out. Not so much of a problem for me anymore anyhow, since I could store the source files in UTF-8 and be done with it.