problems with specials characters

Topics: Developer Forum, Project Management Forum, User Forum
Apr 5, 2011 at 3:32 PM

I'm generating an excel from a data base and I'm having some trouble when I include HTML data, for it doesn't recognize <sub> nor <sup> . Like wise, I need to print &#134; wich would be † and it doesn't recognize phpexcel, so I write $m_titulo = utf8_encode("$datos[titulo]"); but this doesn`t solve my problems. I also included a:

function poncara($texto){
$txt = $texto;
$txt = str_replace("&aacute;","á",$txt);
$txt = str_replace("&eacute;","é",$txt);
$txt = str_replace("&iacute;","í",$txt);
$txt = str_replace("&oacute;","ó",$txt);
$txt = str_replace("&uacute;","ú",$txt);
$txt = str_replace("&Aacute;","Á",$txt);
$txt = str_replace("&Eacute;","É",$txt);
$txt = str_replace("&Iacute;","Í",$txt);
$txt = str_replace("&Oacute;","Ó",$txt);
$txt = str_replace("&Uacute;","Ú",$txt);
$txt = str_replace("&ntilde;","ñ",$txt);
$txt = str_replace("&Ntilde;","Ñ",$txt);

but this doesn't solve my problems with the "sub-index" or characters such as " † ".

For example...while ($data = mysql_fecth_array($sql)){
$objPHPExcel->getActiveSheet()->setCellValue("A2", "State <sup>3</sup>");//Case 1
$m_titulo = utf8_encode(poncara("$data[titulo]"));
$objPHPExcel->getActiveSheet()->setCellValue("A$i", "$m_titulo");//Case 2

Any idea?

Note : I'm generating an excel 2007
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
Apr 7, 2011 at 10:42 PM

If you need to use superscript within a cell, or any other markup, then you'll need to create a rich text run; but PHPExcel (and MS Excel) don't simply allow HTML markup in a cell.

You can also simplify your series of str_replace() calls by using PHP's html_entity_decode() function, which can also handle the conversion of these entities to UTF-8.

Apr 8, 2011 at 10:17 PM

how would this be in an example?

because I tryed with all mentioned above, including &X which is supposed to be for superscripts... but nothing happened. Maybe there is something missing in the code...