Accented characters in tab labels causes Excel 2007 files to be corrupted

Sep 14, 2010 at 4:20 PM

I may have discovered a bug when putting accented characters in the Tab labels.  When I create an excel spreadsheet with French accents in the tabs, the Excel file is corrupt and fails to open.  When I take off the accents, everything is fine.

Have you experienced this issue elsewhere?

Sep 14, 2010 at 4:40 PM

Ensure that you are using UTF-8 rather than ISO-8859-1, using iconv() or the mb_string functions to convert as necessary, or saving your script as a UTF-8 file (without a BOM)

$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setTitle(iconv("ISO-8859-1", "UTF-8", 'éléphant'));
$objPHPExcel->getActiveSheet()->setTitle(iconv("ISO-8859-1", "UTF-8", 'fièvre'));
$objPHPExcel->getActiveSheet()->setTitle(iconv("ISO-8859-1", "UTF-8", 'gâteau'));
$objPHPExcel->getActiveSheet()->setTitle(iconv("ISO-8859-1", "UTF-8", 'aigüe'));
$objPHPExcel->getActiveSheet()->setTitle(iconv("ISO-8859-1", "UTF-8", 'français'));
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
Sep 14, 2010 at 4:48 PM
Ok, your suggestion to UTF8 encode the string worked fine.
Thanks for the rapid response.