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

Sep 14, 2010 at 3: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?

Coordinator
Sep 14, 2010 at 3: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->createSheet();
$objPHPExcel->createSheet();
$objPHPExcel->createSheet();
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle(iconv("ISO-8859-1", "UTF-8", 'éléphant'));
$objPHPExcel->setActiveSheetIndex(1);
$objPHPExcel->getActiveSheet()->setTitle(iconv("ISO-8859-1", "UTF-8", 'fièvre'));
$objPHPExcel->setActiveSheetIndex(2);
$objPHPExcel->getActiveSheet()->setTitle(iconv("ISO-8859-1", "UTF-8", 'gâteau'));
$objPHPExcel->setActiveSheetIndex(3);
$objPHPExcel->getActiveSheet()->setTitle(iconv("ISO-8859-1", "UTF-8", 'aigüe'));
$objPHPExcel->setActiveSheetIndex(4);
$objPHPExcel->getActiveSheet()->setTitle(iconv("ISO-8859-1", "UTF-8", 'français'));
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('accentTest.xlsx');
Sep 14, 2010 at 3:48 PM
Ok, your suggestion to UTF8 encode the string worked fine.
Thanks for the rapid response.
Jonathan